API15:JTable/bind
From Joomla! Documentation
Description
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. Binding is the process where values are copied into their equivalently named instance properties (see examples).
Syntax
bind($from, $ignore=array())
| Argument | Data type | Description | Default |
|---|---|---|---|
| $from | array or object | An associative array or object to be bind to the JTable instance. | |
| $ignore | array or string | An optional array or space separated list of properties to ignore while binding. | array() |
Returns
boolean (true if bind is successful)
Defined in
libraries/joomla/database/table.php
Importing
jimport( 'joomla.database.table' );
Source Body
function bind( $from, $ignore=array() )
{
$fromArray = is_array( $from );
$fromObject = is_object( $from );
if (!$fromArray && !$fromObject)
{
$this->setError( get_class( $this ).'::bind failed. Invalid from argument' );
return false;
}
if (!is_array( $ignore )) {
$ignore = explode( ' ', $ignore );
}
foreach ($this->getProperties() as $k => $v)
{
// internal attributes of an object are ignored
if (!in_array( $k, $ignore ))
{
if ($fromArray && isset( $from[$k] )) {
$this->$k = $from[$k];
} else if ($fromObject && isset( $from->$k )) {
$this->$k = $from->$k;
}
}
}
return true;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples