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 - Upgrade from basic application to Advanced application
Yii2: using find() to filter with attributes and one() performs a select all instead of filtering
Best practices when making a Yii2 Extension
Yii2 Shopping cart — Interface 'backend\models\CartPositionInterface' not found
render page without footer yii2
Pre-Checked CheckboxList in Yii2
Forbidden (#403) - You are not allowed to perform this action [Yii2]
yii2 detailview set value with function htmlspecialchars() expects parameter 1 to be string, object given
Set href =“#” or unset html::a href from grid-view yii2
can use yii2 DepDrop::widget without model?
Yii2 Dynamic Form update Action is not working
Yii2 minifying asset bundles throws error on external library
How to display numbers from 1 to 100 as a dropdownlist in Yii2
Specifying unsigned attribute when using the Schema Builder Trait in MIgrations?
Yii2 adminpanel authorization
Jquery show render page in gridview yii2