/** * Loads and instantiates models required by this controller. * If Controller::persistModel; is true, controller will cache model instances on first request, * additional request will used cached models. * If the model is non existent, it will throw a missing database table error, as Cake generates * dynamic models for the time being. * * @param string $modelClass Name of model class to load * @param mixed $id Initial ID the instanced model class should have * @return mixed true when single model found and instance created error returned if models not found. * @access public */ public function loadModel($modelClass = null, $id = null) { if ($modelClass === null) { $modelClass = $this->modelClass; } $cached = false; $object = null; $plugin = null; if ($this->uses === false) { if ($this->plugin) { $plugin = $this->plugin . '.'; } } list($plugin, $modelClass) = pluginSplit($modelClass, true, $plugin); if ($this->persistModel === true) { $cached = $this->_persist($modelClass, null, $object); } if ($cached === false) { $this->modelNames[] = $modelClass; $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id)); if (!$this->{$modelClass}) { return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base))); } if ($this->persistModel === true) { $this->_persist($modelClass, true, $this->{$modelClass}); $this->_persist($modelClass . 'registry', true, ClassRegistry::objects(), 'registry'); } } else { $this->_persist($modelClass . 'registry', true, $object, 'registry'); $this->_persist($modelClass, true, $object); $this->modelNames[] = $modelClass; } }