yii2


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

Related Links

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

Categories

HOME
pandas
osgi
clips
gerrit
amazon-ec2
hp-exstream
objectgears
framework7
routes
ckeditor
baqend
cross-browser
mouse
podio
paradox
multiple-records
adobe-analytics
fancybox-3
postgres-xl
highlight.js
nodatime
jtextfield
scriptcs
abi
intentfilter
excel-2007
telerik-reporting
captiveportal
jndi
xpages-ssjs
brunch
nhapi
ping
quote
instant-messaging
microsoft-chart-controls
preg-match
bosh
xquery-3.0
semantic-versioning
gtrendsr
avcapturesession
ghost4j
amazon-kinesis-kpl
wixsharp
space-complexity
swift3.0.2
uft-api
reportbuilder
document.write
lumberjack
galen
businessworks
convertapi
celery-task
alphabet
nstextview
carrot
slickedit
r-forge
namecoin
etsy
xml-attribute
markojs
react-native-listview
prettytensor
python-stackless
php-internals
revolution-r
intellij-14
python-3.2
django-unittest
citrus-pay
iis-arr
service-accounts
sysinternals
ami
oberon
lustre
system.reflection
facebook-graph-api-v2.4
knuth
winddk
mdt
wp-query
hyprlinkr
ftps
file-locking
jplaton
comaddin
eventlistener
pvrtc
automount
semantic-diff
asyncfileupload
adk
eclipse-templates
locationlistener
appender
ecl
celltable
revisions
modelstate
preference
fixed-width
backcolor
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App