API16:JForm/bind
From Joomla! Documentation
Contents |
Description
Method to recursively bind values to form fields.
Syntax
bind($data, $limit=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $data | $data An array or object of form values. | |
| $limit | null | $group The group to bind the fields to. |
Returns
boolean True on success, false otherwise.
Defined in
libraries/joomla/form/form.php
Importing
jimport( 'joomla.form.form' );
Source Body
public function bind($data, $limit = null) { // The data must be an object or array. if (!is_object($data) && !is_array($data)) { return false; } // Convert objects to arrays. if (is_object($data)) { // Handle a JRegistry/JParameter object. if ($data instanceof JRegistry) { $data = $data->toArray(); } // Handle a JObject. elseif ($data instanceof JObject) { $data = $data->getProperties(); } // Handle other types of objects. else { $data = (array)$data; } } // Iterate through the groups. foreach ($this->_groups as $group => $fields) { $array = $this->_fieldsets[$group]['array']; if ($array === true) { if(isset($this->_fieldsets[$group]['parent'])) { $groupControl = $this->_fieldsets[$group]['parent']; } else { $groupControl = $group; } } else { $groupControl = $array; } // Bind if no group is specified or if the group matches the current group. if ($limit === null || ($limit !== null && $group === $limit)) { // Iterate through the values. foreach ($data as $k => $v) { // If the field name matches the name of the group and the value is not scalar, recurse. if ($k == $groupControl && !is_scalar($v) && !is_resource($v)) { if(isset($this->_fieldsets[$group]['children'])) { $childgroups = $this->_fieldsets[$group]['children']; array_unshift($childgroups, $group); foreach($childgroups as $cgroup) { $this->bind($v, $cgroup); } } else { $this->bind($v, $group); } } else { // Bind the value to the field if it exists. if (isset($this->_groups[$group][$k]) && is_object($this->_groups[$group][$k])) { $this->_data[$group][$k] = $v; } if (isset($this->_fieldsets[$group]['parent']) && isset($this->_groups[$this->_fieldsets[$group]['parent']][$k]) && is_object($this->_groups[$this->_fieldsets[$group]['parent']][$k])) { $this->_data[$group][$k] = $v; } } } } } return true; }
[Edit See Also] SeeAlso:JForm/bind