Reputation: 2165
I am using CakePhp 2.5 and i am into a view that have the $data array,
This is the result of a search form and i can var_dump and see is there.
How can i pass this same $data array to an action of the same controller that show the output in PDF format? ?
I try :
echo $this->Html->Link("PDF", array('controller' => 'Verify',
'action'=> 'resultsPdf', $data),);
I just get : array (size=0) empty
Upvotes: 0
Views: 69
Reputation: 1656
You can't pass an array as an argument to a controller function like that. One way around that would be to encode the array as a json string, and then decode in the controller action.
$encoded = json_encode($data);
echo $this->Html->Link(
"PDF",
array(
'controller' => 'Verify',
'action'=> 'resultsPdf',
$encoded
)
);
Controller:
function resultsPdf($data) {
$data = json_decode($data);
}
Another approach would be through named parameters:
$encoded = json_encode($data);
echo $this->Html->Link(
"PDF",
array(
'controller' => 'Verify',
'action'=> 'resultsPdf',
'encoded' => $encoded
)
);
Controller:
function resultsPdf() {
$data = json_decode($this->params['named']['encoded']);
}
Upvotes: 1