首页 > 代码库 > Yii 配置文件

Yii 配置文件

主配置文件是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(     ‘basePath‘=>dirname(__FILE__).DIRECTORY_SEPARATOR.‘..‘,     ‘name‘=>‘My Web Application‘,      // preloading ‘log‘ component     ‘preload‘=>array(‘log‘),      // autoloading model and component classes     ‘import‘=>array(         ‘application.models.*‘,         ‘application.components.*‘,     ),      //default controller     ‘defaultController‘=>‘test‘,          //controller map     /* ‘controllerMap‘=>array(         ‘index‘=>‘application.controllers.TestController‘,         ), */                  ‘modules‘=>array(         // uncomment the following to enable the Gii tool                  ‘gii‘=>array(             ‘class‘=>‘system.gii.GiiModule‘,             ‘password‘=>‘mr.coke‘,              // If removed, Gii defaults to localhost only. Edit carefully to taste.             ‘ipFilters‘=>array(‘127.0.0.1‘,‘::1‘),         ),              ),      // 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>‘,                 ‘index‘=>‘test/index‘,                 ‘test‘=>‘test/test‘,             ),         ),                  /* ‘db‘=>array(             ‘connectionString‘ => ‘sqlite:‘.dirname(__FILE__).‘/../data/testdrive.db‘,         ), */         // uncomment the following to use a MySQL database                  ‘db‘=>array(             ‘connectionString‘ => ‘mysql:host=localhost;dbname=user.login.yii‘,             ‘emulatePrepare‘ => true,             ‘username‘ => ‘root‘,             ‘password‘ => ‘root‘,             ‘charset‘ => ‘utf8‘,             ‘tablePrefix‘ =>‘tbl_‘,             ‘enableProfiling‘=>YII_DEBUG,             ‘enableParamLogging‘=>YII_DEBUG,         ),                  ‘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‘,                     ‘levels‘=>‘error, warning,trace‘,                     ‘categories‘=>‘system.db.*‘,                 ),                              ),         ),     ),      // application-level parameters that can be accessed     // using Yii::app()->params[‘paramName‘]     ‘params‘=>array(         // this is used in contact page         ‘adminEmail‘=>‘webmaster@example.com‘,     ), );

 

关于urlmanager:

User-friendly URLs ¶

 

When path is used as the URL format, we can specify some URL rules to make our URLs even more user-friendly. For example, we can generate a URL as short as /post/100, instead of the lengthy/index.php/post/read/id/100. URL rules are used by CUrlManager for both URL creation and parsing purposes.

    ......    components=>array(        ......        urlManager=>array(            urlFormat=>path,            rules=>array(                pattern1=>route1,                pattern2=>route2,                pattern3=>route3,            ),        ),    ),);

The rules are specified as an array of pattern-route pairs, each corresponding to a single rule. The pattern of a rule is a string used to match the path info part of URLs. And the route of a rule should refer to a valid controller route.

Besides the above pattern-route format, a rule may also be specified with customized options, like the following:

pattern1=>array(route1, urlSuffix=>.xml, caseSensitive=>false)

Starting from version 1.1.7, the following format may also be used (that is, the pattern is specified as an array element), which allows specifying several rules with the same pattern:

array(route1, pattern=>pattern1, urlSuffix=>.xml, caseSensitive=>false)

3. Using Named Parameters 使用命名的参数

A rule can be associated with a few GET parameters. These GET parameters appear in the rule‘s pattern as special tokens in the following format:

<ParamName:ParamPattern>

where ParamName specifies the name of a GET parameter, and the optional ParamPattern specifies the regular expression that should be used to match the value of the GET parameter. In case when ParamPatternis omitted, it means the parameter should match any characters except the slash /. When creating a URL, these parameter tokens will be replaced with the corresponding parameter values; when parsing a URL, the corresponding GET parameters will be populated with the parsed results.

Let‘s use some examples to explain how URL rules work. We assume that our rule set consists of three rules:

array(    posts=>post/list,    post/<id:\d+>=>post/read,    post/<year:\d{4}>/<title>=>post/read,)
  • Calling $this->createUrl(‘post/list‘) generates /index.php/posts. The first rule is applied.

  • Calling $this->createUrl(‘post/read‘,array(‘id‘=>100)) generates /index.php/post/100. The second rule is applied.

  • Calling $this->createUrl(‘post/read‘,array(‘year‘=>2008,‘title‘=>‘a sample post‘))generates /index.php/post/2008/a%20sample%20post. The third rule is applied.

  • Calling $this->createUrl(‘post/read‘) generates /index.php/post/read. None of the rules is applied.

更多:http://www.yiiframework.com/doc/guide/1.1/en/topics.url
http://www.cnblogs.com/mrcoke/articles/2407759.html

Yii 配置文件