API16

JTable/bind

From Joomla! Documentation

< API16:JTable
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to bind an associative array or object to the JTable instance.This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.



Syntax[edit]

bind($src, $ignore=array())
Parameter Name Default Value Description
$src An associative array or object to bind to the instance.
$ignore array() An optional array or space separated list of properties to ignore while binding.

Returns[edit]

boolean True on success.

Defined in[edit]

libraries/joomla/database/table.php

Importing[edit]

jimport( 'joomla.database.table' );

Source Body[edit]

public function bind($src, $ignore = array())
{
        // If the source value is not an array or object return false.
        if (!is_object($src) && !is_array($src)) {
                $this->setError(get_class($this).'::bind failed. Invalid source argument');
                return false;
        }

        // If the source value is an object, get its accessible properties.
        if (is_object($src)) {
                $src = get_object_vars($src);
        }

        // If the ignore value is a string, explode it over spaces.
        if (!is_array($ignore)) {
                $ignore = explode(' ', $ignore);
        }

        // Bind the source value, excluding the ignored fields.
        foreach ($this->getProperties() as $k => $v) {
                // Only process fields not in the ignore array.
                if (!in_array($k, $ignore)) {
                        if (isset($src[$k])) {
                                $this->$k = $src[$k];
                        }
                }
        }

        return true;
}



Examples[edit]

Code Examples[edit]