Support Joomla!

references:joomla.framework:application:jmodel-__construct

__construct

API Package Subpackage Class Method Reference Last reviewed Doc status
API Home Package Joomla.Framework Subpackage Application Class JModel Method __construct Reference __construct() Never Work in Progress

JModel constructor.

The constructor will store a reference to the application database connector object, reset the state variables, set the model name (based on the config parameters) and set the table path (again, based on the config parameters).

The $config parameter is an array of configuration values. There are two settings that are currently used. The first is ‘name’, which is the name of the model. The second is ‘table_path’ which is passed to the addTablePath() method.

If the $config parameter is not supplied, then the model name will take on the part of the current class name that occurs after the text Model (so a class named WeblinksModelWeblink would have a model name of Weblink). The table path will default to JPATH_COMPONENT_ADMINISTRATOR.DS.’tables’.

Syntax

JModel construct ( $config ) | $config | array | is an array of configuration settings to use for creating the model. This parameter is optional and if omitted the model will be created as described above. | ===== Examples ===== <code php|Example> jimport( ‘joomla.application.component.model’ ); class HelloModelHellos extends JModel { function construct() {

	$config = array(
		'name' => 'MyModel',
		'table_path' => JPATH_COMPONENT.DS.'tables'
	);
	parent::__construct( $config );
}

}

$model = new HelloModelHellos(); echo $model→_name; print_r( JTable::addIncludePath() ); </code> might produce

Result

MyModelArray
(
    [0] => /var/www/j15/administrator/components/com_poll/tables
    [1] => /var/www/j15/libraries/joomla/database/table
)

 
references/joomla.framework/application/jmodel-__construct.txt (609 views) · Last modified: 2007/08/15 14:49