Difference between revisions of "JController/getModel"
From Joomla! Documentation
< API15:JController
(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...) |
|||
Line 9: | Line 9: | ||
===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 ); |
} | } | ||
} | } |
Revision as of 17:09, 22 March 2010
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Method to get a model object, loading it if required.
Template:Description:JController/getModel
Syntax[edit]
& 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[edit]
object The model.
Defined in[edit]
libraries/joomla/application/component/controller.php
Importing[edit]
jimport( 'joomla.application.component.controller' );
Source Body[edit]
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;
}
[Edit See Also] Template:SeeAlso:JController/getModel
Examples[edit]
<CodeExamplesForm />