
Originally Posted by
Dr Livingston
I would go with having multiple actions on the same controller, as it reduces the complexity on the file system overall; Having individual files in a bid to reduce file size on INCLUDEs makes little difference, as the overhead otherwise is not here nor there in real terms.
You mean something like this:
PHP Code:
<?php
class FrontController {
var $directory;
var $default;
var $error;
var $pre_action = array();
function __construct(&$locator) {
$this->locator =& $locator;
}
function setDirectory($directory) {
$this->directory = $directory;
}
function setDefault(&$action) {
$this->default =& $action;
}
function setError(&$action) {
$this->error =& $action;
}
function addPreMethod($key, &$value) {
$this->pre_method[$key] =& $value;
}
function dispatch($action) {
while ($action) {
$controller = $action->getClass();
$method = $action->getMethod();
$action = NULL;
if ($controller) {
foreach (array_keys($this->pre_method) as $pre_method) {
if (method_exists($controller, $pre_method)) {
$result = $controller->dispatch($pre_method);
if ($result) {
if (is_object($result)) {
$action = $result;
} elseif (is_object($this->pre_method[$pre_method])) {
$action = $this->pre_method[$pre_method];
} else {
$action = $this->error;
}
continue 2;
}
}
}
if (method_exists($controller, $method)) {
$action = $controller->dispatch($method);
}
} else {
$action = $this->error;
}
}
}
}
?>
Bookmarks