-
Notifications
You must be signed in to change notification settings - Fork 0
Controllers
Mobile Mind edited this page Sep 16, 2024
·
4 revisions
Controller
The controller name and method define the route path, Ex.: PersonController with method method create define route /person/create and /person/create/:id.
source $::env(TRAILS_HOME)/controllers/controller.tcl
namespace import ::trails::controllers::Controller
namespace eval ::controllers {
catch {
oo::class create DummyController {
next
superclass Controller
}
}
oo::define DummyController {
constructor {args} {
my variable scaffold route_prefix allowed_methods filters
}
# filter before execute action
method enter {req} { return $req }
# filter after execute action
method leave {req resp} { return $resp }
# filter execute on error
method recover {req err} { my render -body $err }
}
}
Create default actions for index, create, edit, show, update and delete.
Add route prefix, ex.: /api
Change allowed method for action. The default behavior is respond to any method (GET, POST, ect..). But you can change with:
set allowed_methods {action_a get action_b post,put}}
Change route path of controller_name to route_path
set controller filters
set filters {
action {filter_name <enter|leave|recover> <get,post|*>}
}