You are currently reading the 1.2 documentation. Switch to 2.2  2.1  2.0 

Conservative

Conservative model loading is going to be the ideal model loading method for a production environment. This method will lazy load all of the models instead of loading them all when model loading is executed.

Conservative model loading requires that each file contain only one class, and the file must be named after the class. For example, if you have a class named User, it must be contained in a file named User.php.

To use conservative model loading we need to set the model loading attribute to be conservative:

$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);

We already made this change in an earlier step in the bootstrap.php file so you don't need to make this change again.

When we use the Doctrine_Core::loadModels() functionality all found classes will be cached internally so the autoloader can require them later.

Doctrine_Core::loadModels('models');

Now when we instantiate a new class, for example a User class, the autoloader will be triggered and the class is required.

// triggers call to Doctrine_Core::modelsAutoload() and the class is included
$user = new User();

Instantiating the class above triggers a call to Doctrine_Core::modelsAutoload() and the class that was found in the call to Doctrine_Core::loadModels() will be required and made available.

Conservative model loading is recommended in most cases, specifically for production environments as you do not want to require every single model class even when it is not needed as this is unnecessary overhead. You only want to require it when it is needed.


Questions and Feedback

If you find a problem with the documentation or have a suggestion, please register and open a ticket.

If you need support or have a technical question, you can post to the user mailing-list.