【问题标题】:How to install Yiistrap? I got CException Property "CUrlManager.bootstrap" is not defined如何安装 Yiistrap?我得到了 CException 属性“CUrlManager.bootstrap”未定义
【发布时间】:2015-04-12 15:28:44
【问题描述】:

我刚刚安装了 yii 框架,然后我尝试在其上安装 yistrap。我按照以下指南进行操作: http://www.getyiistrap.com/site/startedhttp://www.yiiframework.com/forum/index.php/topic/60019-how-to-install-yiistrap-using-composer/

但它遇到了同样的错误: 异常 属性“CUrlManager.bootstrap”未定义。

我使用 yii-bootstrap-0.9.12.r211 作为成员帖子中的建议:Twitter Bootstrap in Yii,但它仍然不起作用。

我做了 3 处修改:

在extensions/bootstrap/components/Bootstrap.php里面

public function init() {
    $this->registerAllCss();
    $this->registerJs();
    parent::init();
}

config/main.php 里面

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.

Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');

return array(
    ...

    'theme'=>'bootstrap',
    'modules'=>array(
        'gii'=>array(
            'generatorPaths'=>array(
                'bootstrap.gii',
            ),                      
        ),
    ),

    // preloading 'log' component
    'preload'=>array('log'),

    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'bootstrap.helpers.TbHtml',
    ),

    'modules'=>array(
        // uncomment the following to enable the Gii tool
        'gii'=>array(
            ...
          ),
    ),

    // application components
    'components'=>array(

        'user'=>array(
            // enable cookie-based authentication
            'allowAutoLogin'=>true,
        ),

        // uncomment the following to enable URLs in path-format
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),

        'bootstrap'=>array(
        'class'=>'bootstrap.components.Bootstrap',
            ),

        ),

                // database settings are configured in database.php
        'db'=>require(dirname(__FILE__).'/database.php'),

        'errorHandler'=>array(
            // use 'site/error' action to display errors
            'errorAction'=>'site/error',
        ),

        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ),
                // uncomment the following to show log messages on web pages
                /*
                array(
                    'class'=>'CWebLogRoute',
                ),
                */
            ),
        ),

    ),

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
        // this is used in contact page
        'adminEmail'=>'webmaster@example.com',
    ),
);

views/layouts/main.php里面,&lt;head&gt; ... &lt;/head&gt;中间

<?php Yii::app()->bootstrap->register(); ?>

请帮我节省时间。谢谢。

【问题讨论】:

    标签: php css yii installation cexception


    【解决方案1】:

    您已经在 url-manager 数组中定义了 'bootstrap'。这是不正确的。你应该这样做:

    'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),
    
    'bootstrap'=>array(
        'class'=>'bootstrap.components.Bootstrap',
     ),
    

    【讨论】:

    • 谢谢@hamed,第一个障碍已经过去,但它涉及到第二个。我得到了新的 CException: 别名“bootstrap.components.TbApi”无效。确保它指向一个现有的 PHP 文件并且该文件是可读的。 正如 stackoverflow.com/questions/21641401/... 上的建议,我添加了 'import'=>array( ... 'bootstrap.helpers.*', 'bootstrap.widgets. *', 'bootstrap.behaviors.*', ), 到 config/main.php 中,但它没有工作。任何想法? Tx 之前 -
    • 谢谢@hamed,第一个障碍已经过去,但它涉及到第二个。我得到了新的 CException:
      Alias "bootstrap.components.TbApi" is invalid. Make sure it points to an existing PHP file and the file is readable. 我该如何解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多