Sometimes we do not need to install a sophisticated framework. We just want a controller that handles user requests in a simple way. This is what SimpleController does.
For example:
<?php
$c = new SimpleController();
$c->on("start", function () use (&$db) {
// this is a good place to initialize variables
$db = new Database("dbname", "username", "xxx");
});
$c->on("get", function () use (&$username) {
// this is a good place to initialize HTML forms
$username = "<please enter your username here>";
});
$c->on("post", function () use (&$db, $username, $password) {
// this is a good place to perform database operations
$db->addUser($username, $password);
});
$c->on("end", function () use (&$db) {
// this is a good place to close resources
$db->close();
});
// triggers the events 'start', 'get' or 'post' and 'end'
$c->exec();
?>
|