There are currently three methods for including and using models inside your controller. I am referring to the case when your controller does not belong to a model or or the model is not related to the model inside the controller you are working in. Although this case should be extremely rare, it seems to happen to me a lot. This post is basically a re-summary of Gwoo’s response in the CakePHP Google Groups discussion.
1. Controller::loadModel();
This method actually calls ClassRegistry::init() and saves the instance of the model as a parameter in the controller.
Example:
Controller::loadModel('Car');
$cars = $this->Car->find('all');
2. ClassRegistry::init()
This method creates an instance of the Model and returns it for use.
Example:
$car = ClassRegistry::init('Car');
$cars = $car->find('all');
3. App:import() (not recommended)
This method only includes the file. This requires you to create an instance each time.
Example:
App::import('Car');
$car = new Car();
$cars = $car->find('all');
As you can see this is really simple and basic stuff. However, I felt the need to re-post this information. If for nothing else, I will be using this as a reference point for myself
Update 5/27/09: Miles Johnson has a nice write up on this on his blog
