php - yii-boostrap 不加载 css 或 js 文件

标签 php css twitter-bootstrap yii

尝试让 yii boostrap 工作。

在 config/main.php 中

<?php

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

return array(
    'basePath'   => dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..',
    'theme'=>'bootstrap',

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

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

    'modules'    => array(

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

        'admin' => array(
            'components' => array(
                'user'=>array(
                    'class' => 'WebUser',
                    'allowAutoLogin'=>true,
                    'loginUrl' => array('/admin/login'),
                ),
            )
        ),
    ),

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

        'user'         => array(
            'allowAutoLogin' => true,
        ),
        'urlManager'   => array(
            'urlFormat'      => 'path',
            'showScriptName' => false,
            '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' => 'mysql:host=localhost;dbname=xxxx',
            'emulatePrepare' => true,
            'username' => 'xxx',
            'password' => 'xxx',
            'charset' => 'utf8',
        ),
        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),
        'log'          => array(
            'class'  => 'CLogRouter',
            'routes' => array(
                array(
                    'class'  => 'CFileLogRoute',
                    'levels' => 'error, warning',
                ),

                array(
                    'class' => 'CWebLogRoute',
                ),

            ),
        ),
    ),

    'params'     => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    ),
);

在 layouts/main.php 中

我有 Yii::app()->bootstrap->register(); 然后抛出一个错误

include(Bootstrap.php): failed to open stream: No such file or directory

bootstrap.widgets 似乎可以正常工作,因为生成了正确的代码,但缺少用于正确设置所有样式的 css 和 js 文件。

最佳答案

return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'XXXXXX',
    // preloading 'log' component
    'preload' => array('log'),
    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.messages.*',
        'application.components.*',
        'application.extensions.bootstrap.helpers.*',
    ),
    'aliases' => array(
        'bootstrap' => realpath(__DIR__ . '/../extensions/bootstrap'), // change this if necessary
    ),
    'modules' => array(
        'gii' => array(
            'generatorPaths' => array('bootstrap.gii'),
        ),

//        'gii' => array(
//            'class' => 'system.gii.GiiModule',
//            'password' => 'XXXXXX',
//            // If removed, Gii defaults to localhost only. Edit carefully to taste.
//            'ipFilters' => array('XXXXXX'),
//        ),
    ),
    'components' => array(
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
        ),
        'bootstrap' => array(
            'class' => 'bootstrap.components.TbApi',
        ),
        // 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=XXXXXXe',
          'emulatePrepare' => true,
          'username' => 'XXXXX',
          'password' => 'XXXXX',
          'charset' => 'utf8',
          ),

        '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',
    ),
);

关于php - yii-boostrap 不加载 css 或 js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23482359/

相关文章:

html - 当父级具有设置的宽度时,Flex-wrap 属性不响应

javascript - 按钮单击不以弹出窗口形式触发

jquery - PhoneGap、Bootstrap 还是 JQuery Mobile?

javascript - 通过ajax使用下拉表单重新填充多个选择表单

php - 如果 WooCommerce 中的用户是 "logged in",请更改帐户菜单的措辞

javascript - 除非调整窗口大小或单击链接两次,否则同位素 J-query 不会自动排列?

html - div 内的标题用作覆盖。我怎样才能使文本居中?

php - 在 Laravel 5 中使用自定义时间戳返回错误

php - Wordpress SQL 选择多个元值/元键/自定义字段

css - 如何制作占位符和标签过渡?