Any guestbook needs to have some kind of management system for it. This example uses the baseAdminSite component that is provided separately. You can obtain this from the downloads section on SourceForge.
Now that we have our generated and tested DAO object we can look at building the admin pages for it. This requires a little extra work under normal circumstances, however for the sake of simplicity these additional steps are covered in later tutorials.
Once again, return to the command line and head back to the tools folder. We will now run the following script:
php scorpio.php
Any tool or CLI script (if configured) can be executed without any arguments to list the available options - this is built into the CLI application layer.
Any controller needs to be built for a site. You can get the list of currently configured sites by running:
php scorpio.php list sites
Make a note of the site name you want to add the controller to.
To build the admin tools we then issue the following command:
php scorpio.php new controller controlPanel/websiteAdmin/guestbookAdmin --site=baseAdminSite --description="Guestbook Admin" --dao=guestbook
Hit enter and a new set of folders and files should be created. If the guestbook class cannot be loaded, go back and check that the autoload file was created correctly. The folders have all been created in "baseAdminSite/controllers/controlPanel" with first a "websiteAdmin" folder plus 3 files and then a "guestbookAdmin" folder with another 3 files. The templates for the view layer will be in a mirrored set of folders within the baseAdminSite/views folder.
Now before we can use these components, the various files must be edited. First we need to modify the websiteAdmin view. This will simply list sub-controllers and have no actions itself (we could even delete the model file). To do this, open the websiteAdminView.class.php and change the following code:
class websiteAdminView extends mvcView {
/**
* @see mvcViewBase::__construct()
*/
function __construct($inController) {
parent::__construct($inController) ;
}
/**
* Shows the websiteAdminView page
*
* @return void
*/
function showWebsiteAdminPage() {
$this->setCacheLevelNone();
$this->render($this->getTpl('websiteAdmin'));
}
}
to:
class websiteAdminView extends mvcView {
/**
* @see mvcViewBase::__construct()
*/
function __construct($inController) {
parent::__construct($inController) ;
$this->getEngine()->assign('selected', 'controlPanel');
$this->getEngine()->assign('controllerHelpPage', 'websiteAdminController');
$this->getEngine()->assign('parentController', 'home');
}
/**
* Shows the websiteAdminView page
*
* @return void
*/
function showWebsiteAdminPage() {
$this->setCacheLevelNone();
$this->render($this->getTpl('controllerListPage', '/shared'));
}
}
Next, open the guestbookAdminController and Model files. We need to update the filters and make sure that we set the primary key correctly in both the controller and the model. Find the following lines in the controller:
/**
* @see mvcControllerBase::addInputToModel()
*/
function addInputToModel($inData, $inModel) {
/**
* @todo set the primary key here
*/
//$inModel->setPrimaryKey($inData['PrimaryKey']);
$inModel->setId($inData['Id']);
$inModel->setName($inData['Name']);
$inModel->setEmailAddress($inData['EmailAddress']);
$inModel->setIpAddress($inData['IpAddress']);
$inModel->setReferrer($inData['Referrer']);
$inModel->setComment($inData['Comment']);
$inModel->setUpdatedFor($inData['UpdatedFor']);
}
and change it to:
/**
* @see mvcControllerBase::addInputToModel()
*/
function addInputToModel($inData, $inModel) {
$inModel->setId($inData['PrimaryKey']);
$inModel->setName($inData['Name']);
$inModel->setEmailAddress($inData['EmailAddress']);
$inModel->setIpAddress($inData['IpAddress']);
$inModel->setReferrer($inData['Referrer']);
$inModel->setComment($inData['Comment']);
$inModel->setUpdatedFor($inData['UpdatedFor']);
}
Now, in the model update the database and table names in the method getTotalObjects() and finally, again in the model, set the primary key for loading in the method getExistingObject() to use the correct method (setId()).
Save all the changes and switch to your web-browser.
Posted by: Dave Redfern (Writer), in Tutorials on 12 Apr 2008 @ 13:51
Tags: dao, generator, guestbook, mvcgenerator, scorpio, tutorial,
Contents:
Related Articles
This
work is licenced under a
Creative Commons Licence.