JView/setModel: Difference between revisions
From Joomla! Documentation
No edit summary |
m clean up |
||
| Line 2: | Line 2: | ||
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. | 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. | ||
{{Description:JView/setModel}} | |||
{{subst:Description:JView/setModel}} | |||
===Syntax=== | ===Syntax=== | ||
| Line 48: | Line 46: | ||
</source> | </source> | ||
{{subst:SeeAlso:JView/setModel}} | |||
{{SeeAlso:JView/setModel}} | |||
===Examples=== | ===Examples=== | ||
Revision as of 14:38, 24 March 2017
Description
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.
{{subst:Description:JView/setModel}}
Syntax
setModel(&$model, $default=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| &$model | The model to add to the view. | |
| $default | false | Is this the default model? |
Returns
object The added model
Defined in
libraries/joomla/application/component/view.php
Importing
jimport( 'joomla.application.component.view' );
Source Body
function setModel(&$model, $default = false)
{
$name = strtolower($model->getName());
$this->_models[$name] = &$model;
if ($default) {
$this->_defaultModel = $name;
}
return $model;
}
{{subst:SeeAlso:JView/setModel}}
Examples
<CodeExamplesForm />