cakephp controller 加载不相同的 model

1. Controller::loadModel();
This method actually calls ClassRegistry::init() and saves the instance of the model as a parameter in the controller.

Example:

1Controller::loadModel('Car');2$cars = $this->Car->find('all');

2. ClassRegistry::init()
This method creates an instance of the Model and returns it for use.

Example:

1$car = ClassRegistry::init('Car');2$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:

1App::import('Car');2$car = new Car();3$cars = $car->find('all');

posted on 2012-07-03 18:40  一个石头  阅读(168)  评论(0)    收藏  举报