Yii Framework. Set a default action in controller

January 27, 2016 27 egor

Example of set the default action index to any other.

To set the default action from index to any other you want to override property of the class $defaultAction. Example of set the default action with the index on the test:

<?php
 
class MyTestController extends Controller {  
    
    /**
    * Default action
    *
    * @var string
    */
    public $defaultAction = 'test';  
      
    public function actionTest() {  
        //your code
    }  
 
}

After you specify a property of the class $defaultAction application will apply to the test method for the url: index.php?r=myTest or if the included friendly url: /myTest