-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Endel Dreyer edited this page Jan 12, 2015
·
5 revisions
Table of contents
Example of how to define and map a Controller.
config/routes.php
Hook\Http\Router::mount('/', 'MyController');
app/controllers/my_controller.php
class MyController {
public static function mounted($path) {
// Controller successfully mounted at $path
}
// GET /path
function getIndex() {
$this->render('index');
}
// POST /path/create
function postCreate() {
// create
Router::redirect('/');
}
// PUT /path/update
function putUpdate() {
// update
Router::redirect('/');
}
// DELETE /path
function deleteIndex() {
// delete
Router::redirect('/');
}
}
Your application routes should be defined in app/config/routes.php
. The Router
class supports get
, post
, put
, delete
, and any
methods.
Examples:
// Any HTTP verb allowed.
Router::any('/', 'HomeController:index');
// Only GET allowed.
Router::get('/', 'HomeController:show');
// Only POST allowed.
Router::post('/', 'HomeController:create');
// Only PUT allowed.
Router::put('/', 'HomeController:update');
// Only DELETE allowed.
Router::delete('/', 'HomeController:destroy');
hook-framework support both Handlebars and Mustache syntax on its template engine. (thanks to zordius/lightncandy)