API15

API15:JTable/bind

From Joomla! Documentation

Revision as of 22:16, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Binds a named array/hash to this object <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</now...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Binds a named array/hash to this object

[Edit Descripton]

Template:Description:JTable/bind

Syntax

bind($from, $ignore=array())
Parameter Name Default Value Description
$from mixed An associative array or object
$ignore array() mixed An array or space separated list of fields not to bind

Returns

boolean

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;
}

[Edit See Also] Template:SeeAlso:JTable/bind

Examples

<CodeExamplesForm />