Date: Thu, 30 Apr 2009 11:10:16 -0400
From: Randal Rust <randalr...@gmail.com>
To: NYPHP Talk <talk@lists.nyphp.org>
Subject: [nyphp-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
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org/show_participation.php