Tuesday, May 08, 2007

Adding some content to the freshly created php page in KnowledgeTree DMS (KTDMS Series 2)

Carrying forward from the same example as described in series 1, you would obviously want to define and output some data out of the php page you created. In this series we will use the dispatcher and templating classes provided by Knowledgetree to output some simple data out of this page.

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_" that can be called conditionally based on the http request variable "action" (HTTP POST/GET vars). For example, you can define a method "do_createnewrecord" and call the php page with a http request variable "action" of value "createnewrecord", and the page will then automatically look for and execute the "do_createnewrecord" method defined in the page class.

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.

Friday, May 04, 2007

Creating and linking a fresh php page in KnowledgeTree DMS (KTDMS Series 1)

Creating a new php page and linking it on the main page (alongside the dashboard, browse and dms administration hyperlinks) involves several steps described below:




- Create a fresh new php page and make sure you include the following essential includes:

require_once 'config/dmsDefaults.php';
require_once KT_LIB_DIR . '/templating/templating.inc.php';
require_once KT_LIB_DIR . '/templating/kt3template.inc.php';
require_once KT_LIB_DIR . '/dispatcher.inc.php';
require_once KT_LIB_DIR . '/util/ktutil.php';

Let's say the new php page you created is "mytrainingrecords.php" and you want to link the action "mytrainingrecords" to this page. Go into the kt3template.inc.php file and scroll across until you come across the "initMenu" function. Populate the $this->menu array to include the following array item:
"mytrainingrecords" => $this->_actionHelper(array("name"=>_kt("My Training Records"), "action"=>"mytrainingrecords", "active"=>0))

That adds up the additional link on the main horizontal menubar alongside the dashboard and browse links. When somebody clicks on this link, the KTDMS will use the controller page (control.php) to figure out what page to call and it does that by following the mapping defined in the siteMap.php (located in the config directory). Open up the siteMap.php page and add the following php line anywhere:

$default->siteMap->addPage("mytrainingrecords", "/mytrainingrecords.php", "My Training Records", Guest, "mytrainingrecords");


That is pretty much it.

About Me

My photo
Princeton, New Jersey, United States
I am an Information Technology Analyst with extensive background in the Clinical Industry that includes working for CROs, Pharmaceutical and Medical Diagnostic companies.