phpyiiurl-routingyii-componentsyii-url-manager

Redirect without showing default action index - Yii


I want to know if is possible using $this->redirect() statement ,to redirect to a different controller but without showing the action , I mean, if i want to redirect to controller Person by default yii goes to Person/index, I want to redirect to Person (don't want to show the action Person == Person/index)

I know that with $this->redirect() I can use $this->redirect(array(controller/action)), but is always showing the index action.


Solution

  • In your main.php, you should have these default rules in urlManager section:

    '<controller:\w+>/<id:\d+>' => '<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    

    Simply add this above the existing rules:

    '<controller:\w+>/' => '<controller>/index',