views:

38

answers:

1

Hi all,

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

A: 

If you don't want to write the DQL into the Controller (which is a good thing) you can put seperate functions into your model that just work with the functionallity 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 funtions inside the model just as you wanted it.

DrColossos