where we can specify default controller and action

2019-04-20 11:08发布

I have created one project in yii and my default controller points to site controller . I want to change it with some other and where i can specify default controller and action in yii.

标签: php yii
4条回答
Juvenile、少年°
2楼-- · 2019-04-20 11:54

You can add any where in return array protected/main.php

return array(
    ......
    'defaultController' => 'index', 
    ......
);

if you are working in modules base then you can add

'defaultController' => 'shop/index',

Shop is module and index is controller

查看更多
劫难
3楼-- · 2019-04-20 11:55

add the configuration in the config main.php

return array(
    'name' => 'Web Application',
    'defaultController' => 'home', 
    ......
);
查看更多
Explosion°爆炸
4楼-- · 2019-04-20 11:55

Perfect solution for changing the default controller. Part of the question was also to change the default action. If you've set 'defaultController' => 'home', the default action will be 'index' (unless set otherwise), you can change this in the controller like so:

class HomeController extends CController
{

  public $defaultAction = 'someotheraction';

  public function actionSomeotheroaction()
  {

  }

}
查看更多
贼婆χ
5楼-- · 2019-04-20 12:15

You can set controller to Default Controller in project directory protected/main.php add this code in array like $configArray = array()

$configArray =  array
(
    'name'=>'Web Appname',
    'defaultController'=>'index'
    ......
);

And set the default action in Controller

class NameController extends AdminCoreController
{
    public $defaultAction = 'index'; 
}
查看更多
登录 后发表回答