how to run action of frontend controller from backend in yii2
Is it possible to run action of frontend controller from backend? this code works if called action is in backend too. can i specify in runAction that controller/action is in frontend? Yii::$app->runAction('controller/action') Also i' m tried something like $c=new controller(); $s->action(); too but it seems it not working too. //new controller() need some parameters and i have no idea what it is.
The yii\base\Application object has a public property controllerNamespace, which defaults to app\\controllers. You need to change it accordingly to changing default controller namespace. Change namespace in action: Yii::$app->controllerNamespace = 'frontend\controllers' and use runAction
A way could be this . In your backend application config you could create an additional 'UrlManager' component name eg: urlManagerFrontEnd return [ 'components' => [ 'urlManager' => [ // here is your backend URL rules ], 'urlManagerFrontEnd' => [ 'class' => 'yii\web\urlManager', 'baseUrl' => 'http://your_path/frontend/web/index.php', 'enablePrettyUrl' => true, 'showScriptName' => false, ], ], ]; Then you should invoke following to compose front-end URL: Yii::$app->urlManagerFrontEnd->createUrl(); and add the controller/action you prefer remeber that runAction() Runs an action within this controller with the specified action ID and parameters. http://www.yiiframework.com/doc-2.0/yii-base-controller.html#runAction()-detail this mean that cannot run an action of another controller or of another application .. If you need a service then you must configure a RESTFull or you simply need a redirection you can use redirect
Yii2 Noam Image manager save outside web folder
How to access a field from linked table in dropdown list
yii2 asset folder is not writable by web process
How to create a new input field which would offer values stored in different database table? Yii2
yii2: how to exclude DbTarget info from log?
Yii2 site/page 404 error
Yii2. How to set scenario in dataProvider?
Want to get maximal value, but query doesn't work
How to filter column according to it's name in yii2?
yii2 smarty :Change the filename extension from .tpl to .tpl.php
Yii2 extension: How to declare $sourcePath in assets?
Yii2 Mailchimp Integration
Unable to save model attribute as null?
How to add a placeholder to a dropdown in Yii2?
How to use a custom Controller in yii2?
How to disable one prompt value in yii2 drop-down?