微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在尝试为我的视图添加materialize css,这是我的视图/ layouts / index.PHP

<?PHP
use yii\helpers\Html;
use yii\widgets\Menu;

?>
<?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 @R_842_4045@ion.
                            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' => [
                'yii\web\JqueryAsset' => [
                    'js'=>[]
                ],
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'js'=>[]
                ],
                'yii\bootstrap\BootstrapAsset' => [
                    'css' => [],
                ],

            ],
        ],

但它返回:

PHP Notice – yii\base\ErrorException

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 frontend\assets;

use yii\web\AssetBundle;

/**
 * @author Qiang Xue <[email protected]>
 * @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 = [
        # 'yii\web\YiiAsset',
        # 'yii\bootstrap\BootstrapAsset',
    ];


}

解决方法:

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 app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
    'css/path_to_materialize.css',
];
public $js = [
];
public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset',
];

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐