加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在添加Materialise css后尝试在Yii2上获取非对象Error的

发布时间:2020-12-13 15:58:46 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试为我的视图添加materialize css,这是我的视图/ layouts / index.php: ?phpuse yiihelpersHtml;use yiiwidgetsMenu;??php $this-beginPage(); ? html head !--Import materialize.css-- link type="text/css" rel="stylesheet" href="?php ech
我正在尝试为我的视图添加materialize css,这是我的视图/ layouts / index.php:

<?php
use yiihelpersHtml;
use yiiwidgetsMenu;

?>
<?php $this->beginPage(); ?>

    <html>
    <head>
        <!--Import materialize.css-->
        <link
            type="text/css"
            rel="stylesheet"
            href="<?php echo $this->theme->baseUrl; ?>/frontend/web/css/materialize.min.css"
            media="screen,projection"/>
        <link type="text/css"
              rel="stylesheet"
              href="<?php echo $this->theme->baseUrl ?>/frontend/web/css/style.css"
              media="screen,projection"/>

        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <meta name="author" content="Imre Mehesz">
        <meta name="description" content="A simple design based on Material UI and MaterializeCSS.">
        <meta name="robots" content="all">
    </head>

    <body>
    <?php $this->beginBody() ?>
    <div class="container">
        <!-- Navbar goes here -->
        <nav>
            <div class="nav-wrapper">
                <a href="#" class="brand-logo right"><?php echo Html::encode(Yii::$app->name); ?></a>
                <?php
                echo Menu::widget([
                    'options' => [
                        "id" => "nav-mobile","class" => "left side-nav"
                    ],'items' => [
                        ['label' => 'Home','url' => ['site/index']],['label' => 'About','url' => ['site/about']],['label' => 'Contact','url' => ['site/contact']],['label' => 'Login','url' => ['site/login'],'visible' => Yii::$app->user->isGuest],],]);
                ?>
                <a class="button-collapse" href="#" data-activates="nav-mobile"><i class="mdi-navigation-menu"></i></a>
            </div>
        </nav>

        <!-- Page Layout here -->
        <div class="row">

            <div class="right col s12 m8 l9"> <!-- Note that "m8 l9" was added -->
                <p>
                    <?php echo $content; ?>
                </p>
            </div>

            <div class="left col s12 m4 l3"> <!-- Note that "m4 l3" was added -->
                <div class="card">
                    <div class="card-image">
                        <img src="<?php echo $this->theme->baseUrl ?>/frontend/web/images/header.jpg">
                        <span class="card-title">TF Violet</span>
                    </div>
                    <div class="card-content">
                        <p>I am a very simple card. I am good at containing small bits of information.
                            I am convenient because I require little markup to use effectively.</p>
                    </div>
                    <div class="card-action">
                        <a href="#">This is a link</a>
                    </div>
                </div>
            </div>
        </div>

        <footer class="page-footer">
            <div class="container">
                <div class="row">
                    <div class="col l6 s12">
                        <h5 class="white-text">Footer Content</h5>

                        <p class="white-text text-lighten-1">You can use rows and columns here to organize your footer
                            content.</p>
                    </div>
                    <div class="col l4 offset-l2 s12">
                        <h5 class="white-text">Links</h5>
                        <li><a class="white-text" href="#!">Link 1</a></li>
                        <li><a class="white-text" href="#!">Link 2</a></li>
                        <li><a class="white-text" href="#!">Link 3</a></li>
                        <li><a class="white-text" href="#!">Link 4</a></li>
                    </div>
                </div>
            </div>
            <div class="footer-copyright">
                <div class="container white-text center">
                    ? 2015 ThemeFactory.net
                </div>
            </div>
        </footer>

    </div>

    <!--Import jQuery before materialize.js-->
    <script type="text/javascript"
            src="https://code.jquery.com/jquery-2.1.1.min.js">
    </script>
    <script type="text/javascript"
            src="<?php echo $this->theme->baseUrl ?>/frontend/web/js/materialize.min.js">
    </script>
    <script type="text/javascript">
        $(function () {
            $(".button-collapse").sideNav();
        });
    </script>
    <?php $this->endBody(); ?>
    </body>
    </html>
<?php $this->endPage(); ?>

另外,在配置中:

'components' => [
        'assetManager' => [
            'bundles' => [
                'yiiwebJqueryAsset' => [
                    'js'=>[]
                ],'yiibootstrapBootstrapPluginAsset' => [
                    'js'=>[]
                ],'yiibootstrapBootstrapAsset' => [
                    'css' => [],

但它返回:

PHP Notice – yiibaseErrorException

Trying to get property of non-object

这条线是高位的:

href =“theme-> baseUrl;?> /frontend/web/css/materialize.min.css”

我还是不能用这个主题:D

来自:http://www.bsourcecode.com/yiiframework2/install-new-theme-in-yiiframework-2/#sample-theme-layout

AppAssets:

<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace frontendassets;

use yiiwebAssetBundle;

/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        '/frontend/web/css/materialize.css','/frontend/web/css/materialize.min.css',];
    public $js = [
        '/frontend/web/js/materialize.js','/frontend/web/js/materialize.min.js',];
    public $depends = [
        # 'yiiwebYiiAsset',# 'yiibootstrapBootstrapAsset',];


}

解决方法

http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerCssFile()-detail

是Yii方式注册CSS文件,但建议通过assestBundles完成.我现在使用它们而且更喜欢它们.

http://www.yiiframework.com/doc-2.0/yii-web-assetbundle.html

在$css数组中,只列出您要使用的文件.
http://www.yiiframework.com/doc-2.0/guide-structure-assets.html

<?php

namespace appassets;

use yiiwebAssetBundle;

class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
    'css/path_to_materialize.css',];
public $js = [
];
public $depends = [
    'yiiwebYiiAsset','yiibootstrapBootstrapAsset',];

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读