command class
PHP Code:
class MailingListTable extends BaseCommand
{
function MailingListTable()
{
parent::BaseCommand();
// create recordset
$do = new DataObject_db_mysql( $g_conn );
$do->openTable( 'mailinglist' ); // open mysql table
$do->Sort( 'email' ); // sort recordset by email
$do->Filter( 'active' '=', true ); // remove records where active is false
/* create datagrid and pass recordset to datagrid, then set grid properties that determine how the grid will display and function once rendered */
$grid = new HtmlControl_DataGrid( 'DataGrid' );
$grid->attachDataSource( $do );
$grid->CanUpdate=true;
$grid->CanAppend=true;
$grid->CanDelete=true;
$grid->ShowPrimaryKey=true;
$grid->DisplayRows=10; // rows to display page
// create view and pass datagrid to view
$this->_view = new TableView( $grid );
// set template file
$this->_view->getTemplate( '/templates/mailinglist.tpl' );
}
}
view class
PHP Code:
class TableView extends BaseView
{
var $_ctrl;
function TableView( $ctrl )
{
parent::BaseView();
$this->_ctrl = $ctrl;
}
function view()
{
/* note there are some methods in the base class not shown, the view method is invoked by another method that parses the template, then adds the content below */
$this->_ctrl->Render(); // echos the html table
}
}
Bookmarks