Abstract controller class. Controllers should only be created using a Request.
Controllers methods will be automatically called in the following order by the request:
$controller = new Controller_Foo($request);
$controller->before();
$controller->action_bar();
$controller->after();
The controller action should add the output it creates to
$this->response->body($output)
, typically in the form of a View, during the
"action" part of execution.
Class declared in SYSPATH/classes/controller.php on line 3.
Request
$requestRequest that created the controller
Response
$responseThe response that will be returned from controller
Creates a new controller instance. Each controller must be constructed with the request object that created it.
Request
$request
required - Request that created the controllerResponse
$response
required - The request's responsevoid
public function __construct(Request $request, Response $response)
{
// Assign the request to the controller
$this->request = $request;
// Assign a response to the controller
$this->response = $response;
}
Automatically executed after the controller action. Can be used to apply transformation to the request response, add extra output, and execute other custom code.
void
public function after()
{
// Nothing by default
}
Automatically executed before the controller action. Can be used to set class properties, do authorization checks, and execute other custom code.
void
public function before()
{
// Nothing by default
}