【问题标题】:Yii with bootstrap extension,Alias "bootstrap.widgets.TbNavbar" is invalid. Make sure it points to an existing PHP file带有引导扩展的 Yii,别名“bootstrap.widgets.TbNavbar”无效。确保它指向一个现有的 PHP 文件
【发布时间】:2012-09-16 03:20:07
【问题描述】:

我正在尝试将bootstrap extension 与 yii 一起使用,但我不断收到标题中提到的错误,我仔细检查了我的配置文件,但我不知道我做错了什么。这是我的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.
return array(
        'language'=>'en_us',
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'CODEPAC',

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

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

        ),

        'modules'=>array(
                // uncomment the following to enable the Gii tool
                'user'=>array(
                'debug'=>false,
                'userTable'=>'user',
                'translationTable'=>'translation',
                'mailer'=>'PHPMailer',
                'facebookConfig'=>array(
                        'appId'=>'12345',
                        'secret'=>'secret',
                        'domain'=>'localhost',
                        'status'=>true,
                        'xfbml'=>true,
                        'cookie'=>true,
                        'lang'=>'en_US',)
                ),
                 'avatar'=>array(),

                'profile' => array(
                'privacySettingTable' => 'privacysetting',
                'profileFieldTable' => 'profile_field',
                'profileTable' => 'profile',
                'profileCommentTable' => 'profile_comment',
                'profileVisitTable' => 'profile_visit',
                 ),
                 'role' => array(
                'roleTable' => 'role',
                'userRoleTable' => 'user_role',
                'actionTable' => 'action',
                'permissionTable' => 'permission',
                 ),

                'registration' => array(
                 ),


                'gii'=>array(
                        'class'=>'system.gii.GiiModule',
                        'password'=>'password',
                        // If removed, Gii defaults to localhost only. Edit carefully to taste.
                        'ipFilters'=>array('127.0.0.1','::1'),
                        'generatorPaths'=>array('bootstrap.gii',),
                ),

        ),

        // application components
        'components'=>array(
                'bootstrap'=>array(
                'class'=>'ext.bootstrap.components.Bootstrap',),
                'session'=>array(
                'sessionName'=>'SiteSession',
                'class'=>'CHttpSession',
'autoStart'=>true,
                ),
                 'cache'=>array('class'=>'system.caching.CFileCache'),
                        'user'=>array(
                        'class'=>'application.modules.user.components.YumWebUser',
                        // enable cookie-based authentication
                        'allowAutoLogin'=>true,
                         'loginUrl'=>array('//user/user/login'),
                ),
                // 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>',
                        ),*/
                ),
                /*
                'db'=>array(
                        'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
                ),
                // uncomment the following to use a MySQL database
                */


                'db'=>array(
                        'connectionString' => 'mysql:host=localhost;dbname=myDb',
                        'emulatePrepare' => true,
                        'username' => 'myDbUsername',
                        'password' => 'myDbPassword',
                        'charset' => 'utf8',
                        'tablePrefix'=>'',
                ),

                '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'=>'example@example.com',
        ),
        'import'=>array('application.modules.user.models.*',
        'application.models.*',
        'application.components.*',),
);

【问题讨论】:

  • 您是否将引导扩展复制到 protected/extensions/bootstrap 目录并更改了所有者和权限以使其可读?
  • @Spidaboy7 ...粘贴配置时应该更加小心。在将您的所有密码和密钥发布到像这个这样的公共网站之前,请隐藏它们。
  • 感谢 Stu 和 Umair..我非常绝望,以至于我没有花时间发布它..我希望不再犯同样的错误,..@Stephen305,是的..我确实改变了引导下所有文件的权限,扩展名也是可写/可读的!我只是不知道它出了什么问题!
  • @Spidaboy7 你能把TbNavbar.php 在引导扩展文件夹中的完整路径粘贴到这里吗?
  • 是的,它的 protected/extensions/bootstrap/widgets/Tbnavbar.php

标签: php twitter-bootstrap yii


【解决方案1】:

Yii-Bootstrap 不再预加载,所以现在必须使用路径别名。 做这个。下载最新版本的 yii-bootstrap。 在你的 main.php 配置粘贴的第一行:

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

并像这样配置扩展:

'components'=>array(
        [...]
    'bootstrap' => array(
                //'class' => 'ext.bootstrap.components.Bootstrap'),
                'class'=>'bootstrap.components.Bootstrap'),

你就完成了。

如需更多参考资料,请阅读:http://www.cniska.net/yii-bootstrap/setup.html

【讨论】:

    【解决方案2】:

    确保为您解压缩的扩展程序/引导程序分配 [读取] 访问权限。

    如果你在 Mac / Linux 上,执行:

    chmod 755 引导

    在 Windows 上,右键单击文件夹,然后为 Apache 的帐户分配读取权限。有时也可以将读取权限分配给“所有人”(不过,这取决于您是否关心安全性)。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题。我授予扩展文件夹的完全 (777) 权限。

      试试看。

      【讨论】:

        【解决方案4】:

        我在生产服务器上遇到了这个问题,尽管它在本地运行良好。

        解决方案是授予 apache 对 yii 安装的所有权:

        sudo chown www-data:www-data -R /var/www/yourapp
        

        以前的所有权是 root 并且 apache 看不到文件

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-27
          • 1970-01-01
          • 1970-01-01
          • 2013-11-25
          • 1970-01-01
          相关资源
          最近更新 更多