API15:JController/getModel
From Joomla! Documentation
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