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 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?

Categories

HOME
yii2
pdf
gerrit
webpack
isabelle
reserved
mfc
fme
jsp-tags
rsync
jgroups
ip
django-imagekit
portia
kentor-authservices
numeral.js
correlation
spring-tool-suite
task
ibm-odm
libtiff
django-admin
jqwidget
nodatime
nas
visjs
google-search-api
xpages-ssjs
jaxb2
windows-server-2000
tinymce-4
karaf
commit
lxd
hybridauth
android-nestedscrollview
atl
html5-fullscreen
ios5
neuroscience
avro4s
nomethoderror
password-encryption
keydown
import-from-excel
taffy
atomicity
nativeapplication
crypt
imanage
watchconnectivity
setuptools
slicknav
blackberry-10
essence
qgraphicsview
goose
uid
jfugue
unity-networking
spim
xna-4.0
rgeo
processmodel
cisco-ios
census
dundas
fscommand
jsonpickle
knuth
java.util.concurrent
php-5.4
android-radiobutton
fluentautomation
comexception
braille
dealloc
datagridviewcolumn
tidy
excel-2003
html4
orchardcms-1.7
jelly
ocunit
rdoc
jquery-ui-layout
pendrive
gnu-prolog
window-management
tomcat-valve
f#-powerpack
yetanotherforum
self-extracting
locate
imac
gamequery
mozilla-prism
routedevent
photoshop-cs4
avatar
gacutil
msdev

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App