2010-12-22 45 views
3
'urlManager'=>array(
    'urlFormat'=>'path', 
    'rules'=>array(
     '<view>' => array('site/page/view/'), 
     '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
     '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
     //'index' => array('site/index'), 
    ), 
), 

我目前在我的main.php文件中有这个页面。Yii中的静态页面问题

我有的问题是,当我查看/index.php/index我已经显示在页面文件夹的索引页,但是当我到/index.php/about我仍然得到index.php文件中的页面文件夹。

回答

2
'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' => array('site/index'), 
     '<view>' => array('site/page/view/'), 
    ), 
), 

它应该是这样的:

+2

是的,使用规则级联和第一个匹配规则。这意味着如果您的规则与“”之类的基本匹配,您需要将其添加到规则列表的末尾。 – thaddeusmt 2010-12-22 22:37:17

1

现在的规则应该是(至少在1.1.12版本)

'<view:\w+>' => 'site/page', 

这个代码将提供$ _GET [ '视图']到SiteController :: actionPage,例如http://example.com/test将设置$ _GET ['view'] ='test'