Change default controller / action

How to change the default controller / action in the UrlManager ?

You can’t change that in the urlManager, but what you can do of course is:




...


'components' => array(

  'urlManager' => array(

    'rules' => array(

      '' => 'controller/action',

    ),

  ),

),


...



So when you request the index page, the controller "controller" with action "action" will be triggered.

To really modify the core defaults (site/index), you have to modify CWebApplication::defaultController and CController::defaultAction.

In config:




return array(

   

   'defaultController' => 'test',

   

   ...



and in your controller:





class TestController extends CController

{


  public $defaultAction = 'test';


  public function actionTest()

  {


  }


}




I guess the first solution is what you’re looking for?!

For a more dynamic approach to changing the defaultController (amongst other things), look here.

I am a yii newbie…but i wanted to say that the above code worked for me after i added another key value pair to the urlManager array




...


'components' => array(

  'urlManager' => array(

    'urlFormat'=>'path',    //<---------This line

    'rules' => array(

      '' => 'controller/action',

    ),

  ),

),


...



Hello!

I have similiar question

if I type in url name of controller which not exists (let’s say “sdf”) then I get error:

can we do that if unexisted controller is requested then defaultcontroller is used ?