Passing array to requestAction in CakePHP

帅比萌擦擦* 提交于 2019-12-08 02:48:14

问题


I have function

public myfunction($myArray) {
}

I need to pass array("cat", "dog") To action.

$output = $this->requestAction(
    array('controller' => 'app', 'action' => 'myfunction'),
    array("cat","dog")
);

But this passes only cat to my controller action, dog wasn't passed.

I tried this:

$output = $this->requestAction(
    array('controller' => 'app', 'action' => 'myfunction'),
    array("myArray" => array("cat","dog"))
);

But it didn't help. I checked cookbook but couldn't find relevant example. How can I fix this? Thank you


回答1:


Try this code

$this->requestAction(
    array('controller' => 'app', 'action' => 'myfunction'),
        array('pass' => array('dog','cat'))
            );

in Myfunction :

public myfunction() {
    pr($this->params->params['pass']);
}

Tell me if not working...




回答2:


see tho url

http://book.cakephp.org/1.3/view/991/requestAction

how to pass argument in cakephp requestAction?

try this

$option = array("cat_dog"); 

$this->requestAction(array('controller' => 'app', 'action' => 'myfunction'), $option); 

after then get $option array and explode it.

$myArray = explode('_', your get variable); 

pr($myArray);



回答3:


Try:

$output = $this->requestAction(
array('controller' => 'app', 'action' => 'myfunction'),
array("animals" => array("cat"=>"cat","dog"=>"dog"))
);


来源:https://stackoverflow.com/questions/11745671/passing-array-to-requestaction-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!