[nycphp-talk] Help with a CakePHP View
Nate Abele
nate at cakephp.org
Fri May 1 09:14:28 EDT 2009
> Date: Thu, 30 Apr 2009 11:10:16 -0400
> From: Randal Rust <randalrust at gmail.com>
> To: NYPHP Talk <talk at lists.nyphp.org>
> Subject: [nycphp-talk] Help with a CakePHP View
>
> [snip]
>
> $whereClause = '`District`.`id` = "' .
> $this->mrClean->sql($this->passedArgs[0]) . '"';
> $this->set('district', $this->District->find($whereClause));
>
> $this->passedArgs[0] is an integer, the ID of the record.
Hi Randall,
This may or may not fix your problem, but your query syntax is wrong.
Depending on your Cake version, you'll either want this:
$district = $this->District->find(array("District.id" => $this-
>passedArgs[0]));
- or -
$district = $this->District->find('first', array('conditions' =>
array("District.id" => $this->passedArgs[0])));
However, using findById should do effectively the same thing, so why
not use that?
Also, since whatever's in $passedArgs gets passed as parameters to the
action, you could really just do this (assuming this code is called in
an action:
function view($id = null) {
// ...
$district = $this->District->findById($id);
$this->set(compact('district'));
}
Hope that helps,
- Nate Abele
Lead Developer, CakePHP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090501/0e433d5f/attachment.html>
More information about the talk
mailing list