-
Notifications
You must be signed in to change notification settings - Fork 0
Front Controller
inghamn edited this page Dec 10, 2014
·
3 revisions
Apache is configured to send all requests through the Front Controller, index.php.
- Parse the URL of the request
- Create an empty Template
- Check access control
- Load the Controller
- call the Action on the Controller, passing in the Template
- render the Template that comes back
So far, we're able to get away with very simple routing. We just read urls as /controller/action. The default routing code just:
<?php
// Check for default routes
elseif(preg_match('#'.BASE_URI.'(/([a-zA-Z0-9]+))?(/([a-zA-Z0-9]+))?#',
$_SERVER['REQUEST_URI'],
$matches)) {
$resource = isset($matches[2]) ? $matches[2] : 'index';
$action = isset($matches[4]) ? $matches[4] : 'index';
}
This assumes:
- URL matches controller and action names
- There are only two parts to the route parsing
If either of these changes, we'll need to write some more custom route code, or look at adopting some other library for routing. But right now, I'm not seeing anything that we want to do that can't be accomplished with these simple routes.
- Models
- Controllers
- Front Controller
-
Templates
- Partials
- Helpers
- Assets
- Blocks
- Coding Style
- Accessibility (Section 508)
- Progressive Enhancement
- Unobtrusive Javascript