php的yii框架开发总结7

protected\config\main.php是整个网站中很重要的一个文件,引用文件,连接数据库,默认页面等都是在这里设置:

1 'import'=>array(
2         'application.models.*',
3         'application.components.*',
4         'application.extensions.*',
5     ),

这是引进yii相关的组件,其中application.extensions.*是引用的拓展文件,这里我用的是发邮件的mailer文件。

'defaultController'=>'dailyreport',这是网站默认显示的内容;

1         'db'=>array(
2             'connectionString' => 'mysql:host=localhost;dbname=innovation',
3             'emulatePrepare' => true,
4             'username' => 'root',
5             'password' => '',
6             'charset' => 'utf8',
7             'tablePrefix'=>'tbl_'
8         ),

这是连接数据库的语句;

1 'urlManager'=>array(
2             'urlFormat'=>'path',
3             'rules'=>array(
4                 '<controller:\w+>/<id:\d+>'=>'<controller>/view',
5                 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
6                 '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
7             ),
8         ),

这是url显示的设置,比如下面:

array(
    'posts'=>'post/list',
    'post/<id:\d+>'=>'post/read',
    'post/<year:\d{4}>/<title>'=>'post/read',
)

第一个:posts是网站get请求时的参数名,调用$this->createUrl('post/list')生成/index.php/posts。该规则适用。

第二个:post是参数名,<id:\d+>是匹配参数的正则表达式,调用$this->createUrl('post/read',array('id'=>100))生成/index.php/post/100。该规则适用。

第三个:和上一个类似,调用$this->createUrl('post/read',array('year'=>2008,'title'=>'a sample post'))生成/index.php/post/2008/a%20sample%20post

调用$this->createUrl('post/read')产生/index.php/post/read。请注意,没有规则适用。

posted @ 2013-08-10 13:24  楠楠IT  阅读(228)  评论(0)    收藏  举报