Skip to content

Setting Home Page In yii Application With Default Controller And Default Action ?

Last updated on January 17, 2018

We can set or change front page or home page of YII Driven web Application with simple Changes, we can do this with changing a default controller and a default action.

Default Controller : Default Controller can be called , if no controller provided.

Default action: Default Action is controller method, which will be called by the system automatically if no action is provided while calling controller.

To change or set Default Controller in Yii, go to protected/config/main.php. replace ‘site'(Controller) with your controller

set default controller in yii

return array(
  ...
  'defaultController' => 'site', //Here site controller will be used if no controller can be matched.
  ...
);

Changing Default Action: we can change default action in a controller by setting public property $defaultAction value. here is the code

set default controller Action in yii

class SiteController extends CController
{
  public $defaultAction = 'welcome';
 
  public function actionWelcome()
  {
    ...
  }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments