Passing array to requestAction in CakePHP
13,030
Solution 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...
Solution 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);
Related videos on Youtube
Author by
trante
Updated on June 04, 2022Comments
-
trante almost 2 years
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
-
trante over 11 yearsI need to pass an array to action. "return" is not an array?
-
Abid Hussain over 11 yearstry this echo $this->requestAction(array('controller' => 'app', 'action' => 'myfunction'), array('return', 'param' => array("cat","dog"))));
-
Abid Hussain over 11 yearscakephp which ver you have to use
-
Abid Hussain over 11 yearsrequestAction(string $url, array $options) try this $option = array("cat","dog"); $this->requestAction(array('controller' => 'app', 'action' => 'myfunction'), array(return),$option);
-
trante over 11 yearsLast line didn't work. Also array("return"),$option didn't work
-
Abid Hussain over 11 yearstry this $option = array("cat","dog"); $this->requestAction(array('controller' => 'app', 'action' => 'myfunction'), array(),$option);
-
trante over 11 yearsNope :( Errors are: Warning (2): Missing argument Notice (8): Undefined variable: myArray
-
Abid Hussain over 11 yearstry this $option = array("cat","dog"); $this->requestAction(array('controller' => 'app', 'action' => 'myfunction'), $option);
-
trante over 11 yearsThis was my first option. cat is passed but dog didn't passed.
-
Abid Hussain over 11 yearstry 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);
-
Admin over 11 yearsI Think this is an awesome solution @AbidHussain
-
trante over 11 yearsThat works well you saved my day. I couldn't find anything about this from cookbook..