Reputation: 883
Let's say I have a controller called runAction()
in file/test/backend/TestController
, but I want to run the action runAction2
in file/test/frontend/TestController2
(i want to run runAction2()
in runAction()
). How can i do so in yii2?
Upvotes: 0
Views: 247
Reputation: 493
The proper way to run another action is to use runAction method of the application
Yii::$app->runAction('controller/action', ['param'=>'value']);
Upvotes: 0
Reputation: 883
I have found the solution. All I have to do is put the following code at the top of backend/TestController file.
use frontend/TestController2;
and to use a specific action in that controller i have to add the following in backend/TestController file:
runAction()
{
TestController2::runAction2()
}
Upvotes: 0
Reputation: 920
in your
frontend/config/main.php
add URL manager for access backend.
'components' => [
'urlManagerbackend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/test/backend/',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
]
after this create URL to action like below:
Yii::$app->urlManagerbackend->createUrl(['test/runAction2']);
Upvotes: 2