JTable/load
From Joomla! Documentation
< JTable(Difference between revisions)
(→Parameters) |
|||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{review}} | {{review}} | ||
===Syntax=== | ===Syntax=== | ||
| − | ''void'' load ($ | + | ''void'' load ($keys = NULL,$reset = true) |
=== Parameters === | === Parameters === | ||
| Line 10: | Line 10: | ||
!Default | !Default | ||
|- | |- | ||
| − | |$ | + | |$keys |
| − | | | + | |mixed |
| − | | | + | |An optional primary key value to load the row by, or an array of fields to match. |
| + | |''NULL'' | ||
| + | |- | ||
| + | |$reset | ||
| + | |boolean | ||
| + | |True to reset the default values before loading the new row. | ||
|''NULL'' | |''NULL'' | ||
|} | |} | ||
=== Returns === | === Returns === | ||
| − | + | True if successful. False if row not found or on error (internal error state set in that case). | |
=== Description === | === Description === | ||
JTable::load() - Loads a row from the database and binds the fields to the object properties. | JTable::load() - Loads a row from the database and binds the fields to the object properties. | ||
| + | === Preconditions === | ||
| + | JTable is an abstract class. You need to write a child class, to use its functionality. See [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface#Creating the Table Class | Part 4 of the MVC Tutorial]] | ||
| + | |||
===Example=== | ===Example=== | ||
Let's say we have a table, that stores greetings of different languages: | Let's say we have a table, that stores greetings of different languages: | ||
| Line 41: | Line 49: | ||
|} | |} | ||
| − | If we'd like to load the record with the id #3, we can | + | If we'd like to load the record with the id #3, we can call the table object from within the model, and load the record: |
<source lang="php"> | <source lang="php"> | ||
$table = $this->getTable('greeting'); | $table = $this->getTable('greeting'); | ||
| Line 48: | Line 56: | ||
print_r($table); | print_r($table); | ||
echo '</pre>'; | echo '</pre>'; | ||
| + | |||
| + | /* RETURNS: | ||
| + | TableGreeting Object | ||
| + | ( | ||
| + | [id] => 3 | ||
| + | [greeting] => Guten Tag | ||
| + | [language] => German | ||
| + | ) | ||
| + | |||
| + | */ | ||
</source> | </source> | ||
===See also=== | ===See also=== | ||
| − | * [[JTable/ | + | * [[JTable/bind]] |
| + | * [[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)]] | ||
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JTable]]</noinclude> | <noinclude>[[Category:Development]][[Category:Framework]][[Category:JTable]]</noinclude> | ||
Latest revision as of 10:36, 9 August 2011
| This is a article which: needs review. You can help the Joomla! Documentation Wiki by contributing to it. More pages that need help similar to this one are here. If you feel the need is satistified, please remove this notice. While actively editing, consider adding {{inuse}} to reduce edit conflicts. |
Contents |
[edit] Syntax
void load ($keys = NULL,$reset = true)
[edit] Parameters
| Argument | Data type | Description | Default |
|---|---|---|---|
| $keys | mixed | An optional primary key value to load the row by, or an array of fields to match. | NULL |
| $reset | boolean | True to reset the default values before loading the new row. | NULL |
[edit] Returns
True if successful. False if row not found or on error (internal error state set in that case).
[edit] Description
JTable::load() - Loads a row from the database and binds the fields to the object properties.
[edit] Preconditions
JTable is an abstract class. You need to write a child class, to use its functionality. See Part 4 of the MVC Tutorial
[edit] Example
Let's say we have a table, that stores greetings of different languages:
| id | greeting | language |
|---|---|---|
| 1 | Hello | English |
| 2 | Bonjour | French |
| 3 | Guten Tag | German |
If we'd like to load the record with the id #3, we can call the table object from within the model, and load the record:
$table = $this->getTable('greeting'); $table->load(3); echo '<pre>'; print_r($table); echo '</pre>'; /* RETURNS: TableGreeting Object ( [id] => 3 [greeting] => Guten Tag [language] => German ) */