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

前端 未结 5 719
有刺的猬
有刺的猬 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:57

    As of CakePHP 1.2.5, you should be able to pass various parameter types through the second parameter in requestAction(). e.g.:

    $this->requestAction('/users/view', array('pass' => array('123')));
    

    Then in the UsersController:

    function view($id) {
        echo $id; // should echo 123 I believe, otherwise try $this->params['pass'].
    }
    

    Instead of using 'pass' above, you can alternatively try 'form' and 'named' to pass form/named parameters respectively.

提交回复
热议问题