CakePHP: Undefined variable using find and containable
Running into another issue that I just seem cant to find any information what could be causing.
I am declaring variable $makes and inside the view its not finding it.
here is my current code:
function makemodel($id = null) {
$this->Make->id = $id;
$makes = $this->Make->find('all', array(
'conditions' => array('id' => $id),
'contain' => array('Makemodel' => array('Road'))
)
);
}
} ?>
I have also tried this: $this->set->('makes',$this->Make->find(script here));
Any advice would be appreciated thanks!
Are there any开发者_JAVA百科 reference material other than cakePHP's book?
Array ( [0] => Array ( [Make] => Array ( [id] => 1 [url_make] => subaru [MakeName] => Subaru [MakeOrigin] => Japan [Summary] =>
)
[Makemodel] => Array
(
[0] => Array
(
[id] => 1
[ModelName] => Impreza WRX
[make_id] => 1
[Road] => Array
(
[0] => Array
(
[id] => 3
[makemodel_id] => 1
[RoadTypeID] => 1
[name] => Dirt
)
[1] => Array
(
[id] => 4
[makemodel_id] => 1
[RoadTypeID] => 2
[name] => Snow
)
)
)
)
)
)
Assuming that the find call is working correctly, you have to pass the data from your controller to your view using the set()
method.
function makemodel($id = null) {
$this->Make->id = $id;
$makes = $this->Make->find('all', array(
'conditions' => array('id' => $id),
'contain' => array('Makemodel' => array('Road'))
)
);
$this->set(compact('makes'));
}
Is find
returning correct results?
function makemodel($id = null) {
$makes = $this->Make->find('all', array(
'conditions' => array('id' => $id),
'contain' => array('Makemodel' => array('Road'))
)
);
$this->set('makes', $makes);
}
精彩评论