Source code for file /joomla/application/component/model.php
Documentation is available at model.php
* @version $Id: model.php 6523 2007-02-08 02:58:05Z louis $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Base class for a Joomla Model
* Acts as a Factory class for application specific objects and
* provides many supporting API functions.
* @package Joomla.Framework
* @subpackage Application
if (empty( $this->_name ))
if (isset
($config['name'])) {
$this->_name =
$config['name'];
JError::raiseError (500, "JModel::__construct() : Can't get or parse class name.");
// set the default view search path
if (isset
($config['table_path'])) {
} else if (defined( 'JPATH_COMPONENT_ADMINISTRATOR' )){
* Returns a reference to the a Model object, always creating it
* @param string The model type to instantiate
* @param string Prefix for the model class name
* @return mixed A model object, or false on failure
$modelClass =
$prefix.
ucfirst($type);
$result =
new $modelClass();
* Method to set model state variables
* @param string The name of the property
* @param mixed The value of the property to set
* @return mixed The previous value of the property
function setState( $property, $value=
null )
return $this->_state->set($property, $value);
* Method to get model state variables
* @param string Optional parameter name
* @return object The property where specified, the state object where omitted
return $property ===
null ?
$this->_state :
$this->_state->get($property);
* Method to get the database connector object
* @return object JDatabase connector object
* @return string The error message
* @param string The error message
* @return string The new error message
* Method to get a table object, load it if necessary.
* @param string The table name
* @param string The class prefix
* @return object The table
function &getTable($name=
'', $prefix=
'Table')
if($table =
&$this->_createTable( $name, $prefix )) {
* Add a directory where JModel should search for models. You may
* either pass a string or an array of directories.
* @param string A path to search.
* @return array An array with directory elements
if (!empty( $path ) &&
!in_array( $path, $paths )) {
* Adds to the stack of model table paths in LIFO order.
* @param string|arrayThe directory (-ies) to add.
* @param string The query
* @param int The number of records
function &_getList( $query, $limitstart=
0, $limit=
0 )
$db->setQuery( $query, $limitstart, $limit );
$result =
$db->loadObjectList();
* Returns a record count for the query
* @param string The query
return $db->getNumRows();
* Method to load and return a model object.
* @param string $modelName The name of the view
* @return mixed Model object or boolean false if failed
function &_createTable( $name, $prefix =
'Table')
// Build the model class name
$tableClass =
$classPrefix.
$tableName;
$result =
JError::raiseError( 500, 'Table class ' .
$tableClass .
' not found in file.' );
$result =
new $tableClass($db);
* Create the filename for a resource
* @param string $type The resource type to create the filename for
* @param array $parts An associative array of filename information
* @return string The filename
function _createFileName($type, $parts =
array())