0

I created one controller SlideController for manage the slide on my website. But In the SiteController I just want to load some action in the SlideController. Is it possible or not? If it's possible ,how can I?

2 Answers 2

1

Yes, it is possible.

The proper way I think, is to create yii2\base\Action subclasses which contain common actions shared by different controller.

As a reference on how to write Action and how controller links up it, you can read the source code here - https://github.com/yiisoft/yii2/tree/master/framework/rest

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry , I'm really don't understand what it is. Could you give any example?
Basically, there are two ways to define action in controller, one is declaring actionXXX() method (where XXX is the name of the action), another one is returning an array of "action name-value pair" under actions() method. For the second way, examples are inside the link above. Read ActiveController and xxxAction classes.
I know how to create an action , but I don't know how can I access that action from others controller?
I don't quite understand your problem. If you can make ControllerA to access ActionA, why can't you make ControllerB to access ActionA too?
0

You can use this for your need: https://stackoverflow.com/a/30432980/748156

In your case, in SiteController, set it like:

Yii::$app->runAction('slide/action', ['param1'=>'value1', 'param2'=>'value2']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.