我今天刚刚开始使用Yii,我正试图让bootstrap工作。
我尝试按照这些说明http://www.cniska.net/yii-bootstrap/setup.html#setup但它仍然无效。我的 /protected/config/main.php 看起来像这样。
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// Define a path alias for the Bootstrap extension as it's used internally.
// In this example we assume that you unzipped the extension under protected/extensions.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Site',
'theme'=>'bootstrap', // requires you to copy the theme under your themes directory
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class' => 'system.gii.GiiModule',
'password' => '', //Enter Your Password Here
// 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(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
// 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=DBNAME',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'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'=>'admin@blablabla',
),
);
我将此http://www.yiiframework.com/extension/bootstrap/files/yii-bootstrap-2.1.0.r355.zip下载并解压缩到我的 / protected / extensions / bootstrap 中,并且bootstrap文件夹中的文件夹为:
我读到某个地方我需要把Yii::app()->bootstrap->register();
放在某个地方。但我不知道将它放入哪个文件。我尝试将其放入 /protected/config/main.php 但我收到此错误
Fatal error: Uncaught exception 'CException' with message 'Property "CWebApplication.bootstrap" is not defined.' in /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/base/CComponent.php:130 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/base/CModule.php(105): CComponent->__get('bootstrap') #1 /Applications/XAMPP/xamppfiles/htdocs/dev2/protected/config/main.php(10): CModule->__get('bootstrap') #2 /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/base/CApplication.php(133): require('/Applications/X...') #3 /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/YiiBase.php(125): CApplication->__construct('/Applications/X...') #4 /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/YiiBase.php(98): YiiBase::createApplication('CWebApplication', '/Applications/X...') #5 /Applications/XAMPP/xamppfiles/htdocs/dev2/index.php(13): YiiBase::createWebApplication('/Applications/X...') #6 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/dev2/framework/base/CComponent.php on line 130
答案 0 :(得分:0)
您必须将Yii::app()->bootstrap->register();
放在要使用引导程序的位置。通常是主要布局。
将<?php Yii::app()->bootstrap->register(); ?>
添加到<head>
部分某处的 /protected/layouts/main.php 。