2016-11-26 91 views
0

我是YII框架的新手。我必須隱藏默認的控制器名稱和函數名稱。 例如:Url Manager隱藏YII中的控制器名稱和函數名稱

(現有的URL:http://localhost/food/store/home

(必填網址:http://localhost/food/

在Yii框架的配置頁面,他們已經宣佈urlManager爲:

URL管理中配置頁面:

'urlManager'=>array(
    'urlFormat'=>'path', 
    'showScriptName' => false, 
    'rules'=>array(   
     '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
     '<controller:\w+>'=>'<controller>/index', 
     '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
    ), 
    'showScriptName'=>false, 
) 

默認控制器聲明:

'defaultController'=>'store' 

回答

0

您可以在不使用佔位符像<controller><action>創建特定的規則,你只需要確保你的,一般情況下規則之前添加。

'urlManager' => [ 
    'urlFormat' => 'path', 
    'showScriptName' => false, 
    'rules' => [ 
     //Add the rules for the specific cases 
     '' => 'store/home', 

     // The general case rules go after the specific cases 
     '<controller:\w+>/<id:\d+>' => '<controller>/view', 
     '<controller:\w+>' => '<controller>/index', 
     '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
     '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
    ], 
], 
0

使用別名將解決售後服務問題
'urlManager' => array( 'urlFormat' => 'path', 'rules' => array( 'admin' => '/admin/default', 'mobile' => '/mobile/default', 'mobile/<alias:fees|aboutus|contactus|terms|policy|faq|aml|legal|news|testimonial>' => 'mobile/default/<alias>', '<alias:fees|about|contactus|terms|privacypolicy|faq|aml|legal>' => 'site/<alias>', '<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>', '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), 'showScriptName' => false, ),

相關問題