0

I'm new to the YII framework. I have to hide the default controller name and function name. For example:

(Existing URL : http://localhost/food/store/home )

(Required URL : http://localhost/food/ )

In the YII framework config page, they have declared the urlManager as:

URL Manage in config page :

'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,
)

Default Controller Declaration :

'defaultController'=>'store'

2 Answers 2

1

You can create specific rules without using placeholders like <controller> or <action>, you just need to make sure you add them before the rules for the general cases.

'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>',
    ],
],
Sign up to request clarification or add additional context in comments.

Comments

0

use alias will slove the problem
'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, ),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.