I've used this for quite a while now, based on discussion in CakePHP mailing list here.
1. Controller::loadModel('yourmodel'); (preferred)
// in app/controllers/car_controllers.php
Controller::loadModel('Book');
$this->Book->find('all'); // the object initiated and added as a property to the controller, persistModel is enabled
or
2. ClassRegistry::init('yourmodel');
// in app/controllers/car_controllers.php
$book = ClassRegistry::init('Book'); // returns the object
$book->find('all');
[...] this article: Load model dynamically in CakePHP If you enjoyed this article please consider sharing [...]
ReplyDeleteThanks this saved my life!But loadModel is kind of a bummer because you have to call it once for each model you want to load. It would be able to take a list of models.
ReplyDelete