I am in a situation where I am trying to pass a value from a controller action to an element directly.
The only way I know how to do this is with requestAction(), but I don’t like using that feature for resource reasons and its not recommended in the manual.
Can anyone shed some light on another method?
Here is what I have now:
Bird Controller action:
function element_array_pass() {
$this->paginate['Bird'] = array(
'fields' => array('id', 'name'),
'contain' => array('id', 'name'),
'order' => 'Bird.id'
);
$bird_elmnt = $this->paginate('Bird');
$this->set(compact('bird_elmnt', $bird_elmnt));
}
dir: views/elements/element_array_pass.ctp
debug($bird_elmnt); // nothing being passed here.
dir: views/birds/index.ctp
I include the element in this file, but the array will not pass.
echo $this->element('element_array_pass',array("bird_elmnt" => $bird_elmnt)); // call to element.
I would like to include this element in my index.ctp with values passed from the action() I included above.
1 Answer