⇦ Back to AbstractView classMethod setModel
public \Joomla\CMS\MVC\Model\BaseDatabaseModel
setModel
(mixed $model, mixed $default = false)
Method to add a model to the view. We support a multiple model single
view system by which models are referenced by classname. A caveat to the
classname referencing is that any classname prepended by \JModel will be
referenced by the name without \JModel, eg. \JModelCategory is just
Category.
Parameters
- \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The model to add to the view.
- bool $default Is this the default model?
Returns
- \Joomla\CMS\MVC\Model\BaseDatabaseModel The added model.
Since
Method setModel - Source code
/**
* Method to add a model to the view. We support a multiple model single
* view system by which models are referenced by classname. A caveat to the
* classname referencing is that any classname prepended by \JModel will be
* referenced by the name without \JModel, eg. \JModelCategory is just
* Category.
*
* @param BaseDatabaseModel $model The model to add to the view.
* @param boolean $default Is this the default model?
*
* @return BaseDatabaseModel The added model.
*
* @since 3.0
*/
public function setModel($model, $default = false)
{
$name = strtolower($model->getName());
$this->_models[$name] = $model;
if ($default) {
$this->_defaultModel = $name;
}
return $model;
}