Pages in knowledge tree are created by extending the KTStandardDispatcher class. For every custom class you create, it should have at least one method "do_main" which is the first of your methods that gets called automatically when a web user tries to access this page. Additional methods can be defined in the format "do_
Assuming you are already well familiar with the plugins/pages/actions... concepts in ktdms, the following example creates a page plugin class called "MyTrainingRecords", by extending the KTStandardDispatcher class. KTDMS uses the smarty templating system, so I created a test template file called test.smarty that simply outputs a Hello World message. The do_main method calls some of the default variables defined in the KTStandardDispatcher class to instantiate the template and render its output.
//all required includes defined in series 1, plus
require_once KT_LIB_DIR . '/dispatcher.inc.php';
class MyTrainingRecords extends KTStandardDispatcher {
function MyTrainingRecords()
{
//lets add a breadcrumb detail for this page ;optional
$this->aBreadCrumbs = array(
array('action'=>'mytrainingrecords', 'name'=>_kt("My Traininig Records")),
);
return parent::KTStandardDispatcher();
}
function do_main()
{
$oTemplate =& $this->oValidator->validateTemplate('ktabr/test');
$this->oPage->setTitle('My Training Records Page');
return $oTemplate->render();
}
}
$oDispatcher = new MyTrainingRecords();
$oDispatcher->dispatch();
For a plugin page to be meaningful, its class has to be instantiated and dispatched by the dispatcher (by explicitly calling the dispatch method), which is what the last few lines of the above code do.
The below screenshot shows the output of the newly created php page, along with the breadcrumb detail as defined.
No comments:
Post a Comment