$this->find not working in cakePHP
I have a model with the name Deal class Deal extends AppModel
Now in my controller I call a method in the Deal model called getDeal(开发者_Python百科)
$dealInfo = Deal::getDeal($dealID);
I want the info returned to me but the var_dump displays blank
function getDeal($dealID){
$deal = $this->Deal->find('first', array(
'conditions' =>
'Deal.id' =>$dealID
) ,
'fields' => array(
'Deal.id'
) ,
'recursive' => 1,
));
}
This is the first time I'm working in cakePHP, so this question might sound a bit dumb
When you're just using an id as your find condition you can use CakePHP's dynamic finder methods.
Dynamic finders work like this.
$this->Model->findByModelFieldName();
In your example it would be
$this->findById($dealId, array(
'fields' => array('Deal.id'),
'recursive' => 1
));
I don't know if I'm just being mental, but is this simply because you're not returning anything from getDeal()
?
Try adding return $deal;
and see if that helps. Your question doesn't state exactly where you're doing the var_dump
so I might be well off.
Edit:
As per the discussion with you and 8vius, we've established that this isn't right, and you simply need to change $this->Deal->find()
to $this->find()
because its being run from the model.
Check your function declaration, $deal_id
does not exist and as you can see from the parameter you pass to the function which should me $deal_id
and not dealID
. So you have a misdeclared function calling find with a variable that does not exist.
精彩评论