CakePHP: best way to call an action of another controller with array as parameter?

前端 未结 5 696
有刺的猬
有刺的猬 2020-12-02 17:26

In a controller, what is the most appropriate way to call the action of another controller and also pass an array as parameter?

I know that you can use requestAction

5条回答
  •  渐次进展
    2020-12-02 17:52

    Would it be appropriate for you to move the logic from the second controller into its model, then do something like this in your first controller's action?

    $var = ClassRegistry::init('SecondModel')->myMethod($array);
    $this->set(compact('var'));
    

    Then, in the view for the first controller's action, you can use that data.

    I always try to keep controller methods to actions you can hit through the browser, put as much logic in my models, call foreign model methods from controllers actions that need data from models that aren't the model for that controller, then use that data in my views, and if it's data that is viewed frequently, I create an element for it.

提交回复
热议问题