| View previous topic :: View next topic |
| Author |
Message |
plantino
Joined: 13 May 2006 Posts: 96
|
Hey.
If I'm inside a given controller and want to perform actions on another model than the one for that controller, how do I go about it?
Say I have a Foo model and a Bar model, and within my foos_controller.php I want to perform actions on my Bar model, how's the best way of going about it? |
| |
|
|
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
you can do $uses=array('Bar','Foo'); for loading 2 models
Var $uses |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
Aha!
Cool, thanks
Hmm, I'm trying to do a find() with my model
But it's not *finding* anything
I'm doing $this->ModelName->find('"d = $id"); and it isn't returning anything
When I know for a fact that $id is a valid record in my model |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
| D=$id ? |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
Erm, id= even
$this->ModelName->find("id = $id"); |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
Find(array('ModelName.id'=>$id))
Even better, $this->ModelName->id=$id; $data=$this->ModelName->read() |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
That sounds simpler
If I want to modify that particular record, what's the synax?
Say I want to set Model.fieldname = value
After reading in $data, I could do $this->ModelName->save($data); right? |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
| yep |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
Thanks, I confirmed it  |
| |
|
|
|