| API | Package | Subpackage | Class | Method | Reference | Last reviewed | Doc status |
|---|---|---|---|---|---|---|---|
Home |
Joomla.Framework |
Application |
JController |
addModel |
addModel() |
Never | Work in Progress |
Method to get a model object, loading it if required.
This method will use the specified name and prefix to construct a model name and attempt to instantiate an object. The class name used for the model is determined by the specified name appended to the specified prefix (whitespace is removed). If the model class has not been defined, the model paths will be searched and the file (if found) will be loaded.
The model should be stored in a file with the same name as the model.
JModel &getModel ( $name, $prefix )
| $name | string | is a string containing the model name. |
| $prefix | string | is a string containing the class prefix. This parameter is optional and if omitted defaults to a string which is the controller name with the word ‘Model’ appended to the end. |
This method is invoked in the following way:
Example
$model = $this->getModel('weblink');
This will load the model class named ‘WeblinksModelWeblink’. This model was found in the file ‘weblink.php’.