JController/getModel: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to get a model object, loading it if required.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JController/getModel|Edit Des... |
m preparing for archive only |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
<source lang="php">getModel($name= '', $prefix= '', $config=array())</source> | <source lang="php">& getModel($name= '', $prefix= '', $config=array())</source> | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 40: | Line 40: | ||
===Source Body=== | ===Source Body=== | ||
<source lang="php"> | <source lang="php"> | ||
function getModel($name = '', $prefix = '', $config = array()) | function &getModel( $name = '', $prefix = '', $config = array() ) | ||
{ | { | ||
if (empty($name)) { | if ( empty( $name ) ) { | ||
$name = $this->getName(); | $name = $this->getName(); | ||
} | } | ||
if (empty($prefix)) { | if ( empty( $prefix ) ) { | ||
$prefix = $this->getName() . 'Model'; | $prefix = $this->getName() . 'Model'; | ||
} | } | ||
if ($model = & $this->_createModel($name, $prefix, $config)) { | if ( $model = & $this->_createModel( $name, $prefix, $config ) ) | ||
{ | |||
// task is a reserved state | // task is a reserved state | ||
$model->setState('task', $this->_task); | $model->setState( 'task', $this->_task ); | ||
// Lets get the application object and set menu information if its available | // Lets get the application object and set menu information if its available | ||
$app = &JFactory::getApplication(); | $app = &JFactory::getApplication(); | ||
$menu = &$app->getMenu(); | $menu = &$app->getMenu(); | ||
if (is_object($menu)) | if (is_object( $menu )) | ||
{ | { | ||
if ($item = $menu->getActive()) | if ($item = $menu->getActive()) | ||
{ | { | ||
$params = &$menu->getParams($item->id); | $params =& $menu->getParams($item->id); | ||
// Set Default State Data | // Set Default State Data | ||
$model->setState('parameters.menu', $params); | $model->setState( 'parameters.menu', $params ); | ||
} | } | ||
} | } | ||
| Line 72: | Line 73: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getModel | category=getModel | ||
category=JController | category=JController | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 00:24, 25 March 2017
Description
Method to get a model object, loading it if required.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
& getModel($name= '', $prefix= '', $config=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $name | The model name. Optional. | |
| $prefix | The class prefix. Optional. | |
| $config | array() | Configuration array for model. Optional. |
Returns
object The model.
Defined in
libraries/joomla/application/component/controller.php
Importing
jimport( 'joomla.application.component.controller' );
Source Body
function &getModel( $name = '', $prefix = '', $config = array() )
{
if ( empty( $name ) ) {
$name = $this->getName();
}
if ( empty( $prefix ) ) {
$prefix = $this->getName() . 'Model';
}
if ( $model = & $this->_createModel( $name, $prefix, $config ) )
{
// task is a reserved state
$model->setState( 'task', $this->_task );
// Lets get the application object and set menu information if its available
$app = &JFactory::getApplication();
$menu = &$app->getMenu();
if (is_object( $menu ))
{
if ($item = $menu->getActive())
{
$params =& $menu->getParams($item->id);
// Set Default State Data
$model->setState( 'parameters.menu', $params );
}
}
}
return $model;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples