Lets set the stage using a single index.php as the entry point and using a switch() we delegate actions to certain "modules" or "pages"
Nomenclature is *not* important in this excersize I need practical *not* perfect.
Assume a Smarty 'like' template engine
Code: Select all
$tpl = new Smarty(); // Ignore incorrect API
switch($_GET['page']){
case 'login_form':
{
$buff = $tpl->fetch('login_form.tpl');
break;
}
case 'do_login':
{
$ret = attemptLogin($_POST['user'], $_POST['pass']);
if($ret)
header("Location: index.php?msg=success");
else
header("Location: index.php?msg=failure ");
exit;
}
$tpl->assign('body', $buff);
echo $tpl->fetch('layout.tpl');
}From the above code I can make the following observations:
1) Both view/page selection and action/event handling is unorganzied
2) If a single event was attached to each view we could just have the event handler CASE come before the view selection CASE statement and use a fall through technique - so events are handled before view selection. This is of course impractical as many views have two or more events.
3) The order of execution is important (see #2) we should have events handled before view selection - as this would allow me to avoid using header() redirect's in some instances.
Any more?
Remember, I am *not* looking for a full blown MVC implementation but rather baby steps I can take to clean it up - nor am I looking for definitions of what a front controller is or is not. You can use pattern definitions, but use them loosely.
As it stands a page is a view and visa-versa and an event is an action and so on...
Knowing this, where would you start? What steps would you take to modularize this massive front controller (so to speak)?
I don't wish to write a fancy URL decomposition routine but need to stick with an approach which has a minimal impact as possible.
Suggestions, comments, ideas, etc???
Cheers