CodeIgniter + Doctrine: CRUD in Controller?
I am a newbie to MVC, CodeIgniter and Doctrine, so maybe my question is not that relevant. Pardon me if thats the开发者_高级运维 case.
I've been reading the CodeIgniter + Doctrine tutorials on PHPandStuff.com. I really like whatever I have seen of Doctrine and wish to use it for my project. However, since all database related operations should be kept in the Model and not the Controller, shouldnt the CRUD operations which use Doctrine also be loacted in the Doctrine Model instead? If so, then how?
Thanks in advance
If you don't want to write the DQL into the Controller (which is a good thing) you can put separate functions into your model that just work with the functionality provided by the extended classes.
For example, if you have a class called User
, and you need to save it, you simple could do
class User extends BaseUser //or whatever you want
{
public function saveNewUser($data) {
//setting the userdata e.g. $this->username
try {
$this->save();
....
} catch (Doctrine_Connection_Mysql_Exception $e) {
...
}
}
}
So you have all functions inside the model just as you wanted it.
精彩评论