API16

JTableUser/bind: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Method to bind the user, user groups, and any other necessary data. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JTableUser/bind...
 
m clean up
Line 2: Line 2:
Method to bind the user, user groups, and any other necessary data.
Method to bind the user, user groups, and any other necessary data.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JTableUser/bind|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JTableUser/bind}}
 
{{subst:Description:JTableUser/bind}}


===Syntax===
===Syntax===
Line 78: Line 76:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JTableUser/bind|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JTableUser/bind}}
</span>
{{SeeAlso:JTableUser/bind}}


===Examples===
===Examples===

Revision as of 14:31, 24 March 2017

Description

Method to bind the user, user groups, and any other necessary data.


{{subst:Description:JTableUser/bind}}

Syntax

bind($array, $ignore= '')
Parameter Name Default Value Description
$array $array The data to bind.
$ignore $ignore An array or space separated list of fields to ignore.

Returns

boolean True on success, false on failure.

Defined in

libraries/joomla/database/table/user.php

Importing

jimport( 'joomla.database.table.user' );

Source Body

function bind($array, $ignore = '')
{
        if (key_exists('params', $array) && is_array($array['params'])) {
                $registry = new JRegistry();
                $registry->loadArray($array['params']);
                $array['params'] = (string)$registry;
        }

        // Attempt to bind the data.
        $return = parent::bind($array, $ignore);

        // Load the real group data based on the bound ids.
        if ($return && !empty($this->groups))
        {
                // Set the group ids.
                JArrayHelper::toInteger($this->groups);
                $this->groups = array_fill_keys(array_values($this->groups), null);

                // Get the titles for the user groups.
                $this->_db->setQuery(
                        'SELECT `id`, `title`' .
                        ' FROM `#__usergroups`' .
                        ' WHERE `id` = '.implode(' OR `id` = ', array_keys($this->groups))
                );
                $results = $this->_db->loadObjectList();

                // Check for a database error.
                if ($this->_db->getErrorNum()) {
                        $this->setError($this->_db->getErrorMsg());
                        return false;
                }

                // Set the titles for the user groups.
                for ($i = 0, $n = count($results); $i < $n; $i++) {
                        $this->groups[$results[$i]->id] = $results[$i]->title;
                }
        }

        return $return;
}


{{subst:SeeAlso:JTableUser/bind}}

Examples

<CodeExamplesForm />