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?
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']);
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()
}
运行其他动作的正确方法是使用应用程序的runAction方法
Yii::$app->runAction('controller/action', ['param'=>'value']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.