API16

JTable/ construct: Difference between revisions

From Joomla! Documentation

m clean up
m preparing for archive only
 
Line 4: Line 4:




{{subst:Description:JTable/__construct}}
 


===Syntax===
===Syntax===
Line 69: Line 69:




{{subst:SeeAlso:JTable/__construct}}
 


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=__construct
  category=__construct
  category=JTable
  category=JTable
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:09, 25 March 2017

Description

Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.



Syntax

__construct($table, $key, &$db)
Parameter Name Default Value Description
$table Name of the table to model.
$key Name of the primary key field in the table.
&$db connector object.

Defined in

libraries/joomla/database/table.php

Importing

jimport( 'joomla.database.table' );

Source Body

function __construct($table, $key, &$db)
{
        // Set internal variables.
        $this->_tbl             = $table;
        $this->_tbl_key = $key;
        $this->_db              = &$db;

        // Initialise the table properties.
        if ($fields = $this->getFields()) {
                foreach ($fields as $name => $v) {
                        // Add the field if it is not already present.
                        if (!property_exists($this, $name)) {
                                $this->$name = $v->Default;
                        }
                }
        }

        // If we are tracking assets, make sure an access field exists and initially set the default.
        if (property_exists($this, 'asset_id')) {
                jimport('joomla.access.rules');
                $this->_trackAssets = true;
                // TODO: Do we need the following line anymore?
                //$this->access = (int) JFactory::getConfig()->getValue('access');
        }

        // If the acess property exists, set the default.
        if (property_exists($this, 'access'))
        {
                $this->access = (int) JFactory::getConfig()->getValue('access');
        }
}



Examples

Code Examples