How get any controller->id from current controller,like if I in the default site controller and I write Yii::$app->controller->id/index
it gives me the site/index
,but if I have another controller like named student(and I am in the site controller) how can I redirected to student/index
.
Asked
Active
Viewed 320 times
2

Muhammad Younus
- 1,896
- 19
- 20
2 Answers
2
You can use redirect
return $this->redirect('/your-controller/your-actionindex',302);
or simply without return
$this->redirect('/user/index',302);

ScaisEdge
- 131,976
- 10
- 91
- 107
0
Controller Id :
$this->id
Here $this refers to controller.
And For getting action id :
$this->action->id
If you are using out of controller then
Yii::app()->controller->id
or
Yii::app()->getController()->getId()

Bhavin Solanki
- 1,364
- 11
- 27
-
It's Yii2 not Yii1. – Insane Skull Jul 11 '16 at 09:45
-
But its return controller id in Yii2 also [http://stackoverflow.com/questions/27796371/how-can-i-get-current-controller-in-yii2] ( For Ref.) – Bhavin Solanki Jul 11 '16 at 09:49