yii-boostrap不加载css或js文件

时间:2014-05-05 21:38:15

标签: 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',
    ),
);
布局/ main.php中的

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

  

include(Bootstrap.php):无法打开流:没有这样的文件或   目录

bootstrap.widgets似乎正在生成正确的代码,但缺少的是用于正确设置所有内容的css和js文件。

1 个答案:

答案 0 :(得分:1)

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