The public properties relate directly to the
fields and must have exactly the same names. We use these properties as a 'buffer' to
store individual records.
The second thing we need to do is to define the constructor. In order to use the
JTable::getInstance() method, we must override the JTable constructor with a
constructor that has a single referenced parameter, the database object.
The third thing we need to do is override the check() method. This method is
used to validate the buffer contents, returning a Boolean result. If a check() fails
we use the setError() method to set a message that explains the reason why the
validation failed.
Chapter 3
[ 53 ]
/**
* #__myextenstion_foobars table handler
*
*/
class TableFoobar extends JTable
{
/** @var int Primary key */
var $id = null;
/** @var string Content */
var $content = null;
/** @var int Checked-out owner */
var $checked_out = null;
/** @var string Checked-out time */
var $checked_out_time = null;
/** @var string Parameters */
var $params = null;
/** @var int Order position */
var $ordering = null;
/** @var int Number of views */
var $hits = null;
/**
* Constructor
*
* @param database Database object
*/
function __construct( &$db )
{
parent::__construct('#__myextension_foobars', 'id', $db);
}
/**
* Validation
*
* @return boolean True if buffer is valid
*/
function check()
{
if(!$this->content)
{
$this->setError(JText::_('Your Foobar must contain some
content'));
return false;
}
return true;
The Database
[ 54 ]
}
}
Now that we have created our TableFoobar class what do we do with it? Well
first of all we need to instantiate a TableFoobar object using the static JTable::
getInstance() method.
Pages:
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84