In my controller, I have a function (getRelatedStuff) that returns an array of values for use in my edit.ctp:
class MyController extends AppController {
public function edit($id = null) {
$this->getRelatedStuff($current['Form']['id'];
}
public function getRelatedStuff($id = null) {
$this->loadModel('Related');
$related = $this->Related->find('all', array(
'conditions'=>array('Related.id' => $id)
);
return $this->set(compact('related'));
}
}
This works fine when I use it in edit.ctp in a foreach loop.
foreach($related as $r) {
echo $r['Model']['field'];
}
However, I'm unable to use $related within my edit function itself, and I need access to that data for another purpose. Specifically, I need to set up a foreach() loop within function edit using $related. If I try to do so, or if I try debug $related within the edit function, I always get:
undefined variable $related in /docpath
What can I do to be able to use $related within my edit function?