Controller Plugin
miControllerPlugin class defines three methods to extend the functionality of the controller object. These 3 methods are called at specific times during the processing of the request.
Use:
* preProcessAction() to execute specific code before the action is processed.
* postProcessAction() to implement functionality which is executed after the action is processed.
* processActionStep() to execute code at some step in the processing of actions. Action step can be 'preShowForm', 'postCreate', 'postUpdate', etc., and depend on the specific action.
* Usage of the miControllerPlugin class
<?php
class miWriteToLogPlugin extends miControllerPlugin {
const LOG_FILE = '/tmp/debug.log';
const DATE_FORMAT = 'Y-m-d H:i:s';
public function processActionStep($action, $actionStep)
{
switch ($actionStep)
{
case 'postCreate':
$this->log('Object is being created');
break;
case 'postUpdate':
$this->log('Object is being updated');
break;
}
}
public function postProcessAction($action, $actionResult)
{
if ($action instanceof miExecCreateAction) {
if ($actionResult)
$this->log('Object created successfuly');
else
$this->log('Error occured while creating the object');
}
else if ($action instanceof miExecEditAction) {
if ($actionResult)
$this->log('Object updated successfuly');
else
$this->log('Error occured while updating the object');
}
}
public function log($message)
{
file_put_contents(self::LOG_FILE, date(self::DATE_FORMAT) . ': ' . $message, FILE_APPEND);
}
}
$dataManager->registerPlugin(new miWriteToLogPlugin());
?>