JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
$table = JTable::getInstance('foobar', 'Table');
Note that instead of including the foobar.php file, we tell JTable where the containing
folder is. When JTable comes to instantiate the TableFoobar object, if the class is not
defined, it will look in all of the JTable include paths for a file named foobar.php.
CRUD
CRUD (Create Read Update Delete) is the name given to the four common
data manipulation tasks. We will follow a record through its short 'CRUDy' life.
Throughout the CRUD examples $table refers to an instance of the TableFoobar
class and $id refers to the ID of the record we are dealing with. In this example, we
create a new record; $table is an instance of the TableFoobar class.
$table->reset();
$table->set('content', "Lorem ipsum dolor sit amet");
$table->set('ordering', $table->getNextOrder());
if ($table->check())
{
if (!$table->store())
{
// handle failed store
// use $table->getError() for an explanation
}
}
else
{
// handle failed check
// use $table->getError() for an explanation
}
The reset() method ensures that the table buffer is empty.
Pages:
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85