Difference between revisions of "JTable/bind"
From Joomla! Documentation
< API15:JTable
(New page: ===Description===
Binds a named array/hash to this object
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</now...) |
(Fix another red link) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
===Description=== | ===Description=== | ||
− | + | Method to bind an associative array or object to the [http://api.joomla.org/1.5/Joomla-Framework/Table/JTable.html 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=== | ===Syntax=== | ||
<source lang="php">bind($from, $ignore=array())</source> | <source lang="php">bind($from, $ignore=array())</source> | ||
− | + | {| class="wikitable" | |
− | + | !Argument | |
− | ! | + | !Data type |
− | ! | ||
!Description | !Description | ||
+ | !Default | ||
|- | |- | ||
− | | $from | + | |$from |
− | | | + | |array or object |
− | | | + | |An associative array or object to be bind to the [http://api.joomla.org/1.5/Joomla-Framework/Table/JTable.html JTable] instance. |
+ | | | ||
|- | |- | ||
− | | $ignore | + | |$ignore |
− | | array | + | |array or string |
− | | | + | |An optional array or space separated list of properties to ignore while binding. |
+ | |array() | ||
|} | |} | ||
===Returns=== | ===Returns=== | ||
− | boolean | + | boolean (true if bind is successful) |
===Defined in=== | ===Defined in=== | ||
Line 66: | Line 62: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
− | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
Line 81: | Line 76: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | |||
+ | ===See also=== | ||
+ | * [http://api.joomla.org/Joomla-Framework/Table/JTable.html#bind JTable->addIncludePath on api.joomla.org] | ||
+ | * [[JTable/load|JTable->load]] | ||
+ | * [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Creating a JTable Child Class (MVC Tutorial Part 4)]] | ||
+ | |||
+ | [[Category:Archived pages API15]] |
Revision as of 03:14, 3 July 2013
The "API15" 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. Binding is the process where values are copied into their equivalently named instance properties (see examples).
Syntax[edit]
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[edit]
boolean (true if bind is successful)
Defined in[edit]
libraries/joomla/database/table.php
Importing[edit]
jimport( 'joomla.database.table' );
Source Body[edit]
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[edit]