Lightweight MVC
The goal: to create a lightweight framework that allows web entities to be rendered and served back to an HTTP client., (*1)
The result: Pandora, a small package that simplifies creation of dynamic web pages by assuming things about where your site's assets live., (*2)
Take a composer dependency on pandora-mvc:, (*3)
{ "require": { "zutto/pandora-mvc": "dev-master" } }
Provide Pandora with the runtime configuration it needs in your index.php:, (*4)
PageDispatcher::registerLoader( $your_autoloader_for_controllers ); PageDispatcher::registerLoader( $your_autoloader_for_models ); EnvironmentFactory::setConfigFile(dirname(__FILE__)."/conf/environment.json"); FrontController::render(DEFAULT_PAGE, DEFAULT_ACTION);
The 3 parts:, (*5)
Your controllers will simply be generic classes where each method is mapped to a page., (*6)
When a page is requested, the lifecycle looks like this:, (*7)
Here's an example of a controller for an operation that gives a formatted date:, (*8)
class TimeController { protected $request; public function __construct( Request $request ) { $this->request = $request; } public function format() { $fmt = $this->request->get('format', 'You must specify a date format'); return array ( 'timestamp' => date($fmt) ); } }
If you've set up a configuration like the one in the section above, TimeController::format() will be called whenever someone sends a request to:, (*9)
index.php?page=time&action=format
By accessing that URL, Pandora will execute the format method and try to load a view file in views/time/method.html.php--or method.json.php if the request specified application/json as the Accept-type., (*10)