How should I refactor switch to front controller design?
Posted: Sun Mar 18, 2007 11:29 pm
Refactoring a rather large switch statement like application...
Inside the index.php before the first switch, I have initialize the master template.
Each switch CASE looks something:
Each of those switch statement might have an arbitrary level of nested switch statements which basically further refine the handling behevior or GUI based on levels and templates, included, etc...
Still with me? Good
Like I said originally, the master template is initialized before the first switch because it's the common peice throughout the applicaiton - makes sense.
Where would I refactor this code to? Should it stay in the index.php or move into a master controller class? Should I use a intercepting filter?
Considering the arbitrarty levels of nesting, how would this best be broken up to be mroe MVC friendly? Using a front controller (model 2) design.
I envision the index.php to basically:
- Include required includes
- Authentication
- Application wide initialization
Here is another caveat: What do I do with scripts whose sole purpose was to execute some action (create a user) and redirect back? How does that fit into the MVC/Front Controller design?
Should I have two first line controllers:
- Master controller (initializes master template, etc)
- Action controller (carry out actions *only*) and continue to success messages or original screen, etc
The action controller could potentially grow to ugly girth by using this approach, I could probably break it up like the template controller, in that the first line controller would handle CRUD operations and each CRUD function would further delegate to another specialized controller and so on...this is something like the technique I want to use with the template controller as well.
Cheers
Inside the index.php before the first switch, I have initialize the master template.
Each switch CASE looks something:
Code: Select all
switch($page){
case 'homepage':
break
case 'addresses':
break;
case 'statistics':
break;
case 'admin':
break;
}Still with me? Good
Like I said originally, the master template is initialized before the first switch because it's the common peice throughout the applicaiton - makes sense.
Where would I refactor this code to? Should it stay in the index.php or move into a master controller class? Should I use a intercepting filter?
Considering the arbitrarty levels of nesting, how would this best be broken up to be mroe MVC friendly? Using a front controller (model 2) design.
I envision the index.php to basically:
- Include required includes
- Authentication
- Application wide initialization
Here is another caveat: What do I do with scripts whose sole purpose was to execute some action (create a user) and redirect back? How does that fit into the MVC/Front Controller design?
Should I have two first line controllers:
- Master controller (initializes master template, etc)
- Action controller (carry out actions *only*) and continue to success messages or original screen, etc
The action controller could potentially grow to ugly girth by using this approach, I could probably break it up like the template controller, in that the first line controller would handle CRUD operations and each CRUD function would further delegate to another specialized controller and so on...this is something like the technique I want to use with the template controller as well.
Cheers