This example loads the new record from the table into
the buffer.
$table->load($table->id);
Now the buffer will look like this:
[id] => 1
[content] => Lorem ipsum dolor sit amet
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[params] =>
[ordering] => 1
[hits] => 0
Instead of loading newly added records, we could modify the TableFoobar class so
that the default values correspond directly to the database table's default values. This
way we reduce our overheads and do not have to reload the record.
However, because some of the default values are dependent upon the database, to
do this we would have to modify the constructor and override the reset() method.
For example the checked_out_time field default value is $db->getNullDate(), and
we cannot use this when defining parameters.
The Database
[ 56 ]
The way we updated the table buffer after creating the new record is precisely the
same way we would load (read) any existing record. This example shows how we
load a record into the buffer:
if (!$table->load($id))
{
// handle unable to load
// use $table->getError() for an explanation
}
Well, we are steaming through this CRUD (not literally).
Pages:
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87