2010-12-22 205 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'