Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing array to requestAction in CakePHP

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

like image 796
trante Avatar asked Feb 27 '26 12:02

trante


2 Answers

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...

like image 177
Krishna Avatar answered Mar 01 '26 00:03

Krishna


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);
like image 41
Abid Hussain Avatar answered Mar 01 '26 01:03

Abid Hussain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!