Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where we can specify default controller and action in yii

Tags:

php

yii

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.

like image 626
preet's Avatar asked Oct 22 '12 09:10

preet's


People also ask

What is an action in yii?

Action is the base class for all controller action classes. An action method in an Action class can be used in multiple controllers or in different projects. Derived classes must implement a method named run() . This method will be invoked by the controller when the action is requested.

What is $App in yii?

Applications are objects that govern the overall structure and lifecycle of Yii application systems. Each Yii application system contains a single application object which is created in the entry script and is globally accessible through the expression \Yii::$app .

How can I get current URL in yii?

Yii::app()->request->getUrl() method is used to get current url in Yii framework.

What is module in yii?

A module is an entity that has its own models, views, controllers, and possibly other modules. It is practically an application inside the application. Step 1 − Create a folder called modules inside your project root. Inside the modules folder, create a folder named hello.


3 Answers

add the configuration in the config main.php

return array(
    'name' => 'Web Application',
    'defaultController' => 'home', 
    ......
);
like image 103
raghul Avatar answered Nov 15 '22 17:11

raghul


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()
  {

  }

}
like image 33
Raz0rwire Avatar answered Nov 15 '22 15:11

Raz0rwire


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

like image 43
Nanhe Kumar Avatar answered Nov 15 '22 16:11

Nanhe Kumar