This class is a transparent base class for Controller_Template and should not be accessed directly.
Abstract controller class for automatic templating.
Class declared in SYSPATH/classes/Kohana/Controller/Template.php on line 12.
boolean
$auto_renderauto render template
bool TRUE
Request
$requestRequest that created the controller
NULL
Response
$responseThe response that will be returned from controller
NULL
View
$templatepage template
string(8) "template"
Assigns the template View as the request response.
public function after()
{
if ($this->auto_render === true) {
$this->response->body($this->template->render());
}
parent::after();
}
Loads the template View object.
public function before()
{
parent::before();
if ($this->auto_render === true) {
// Load the template
$this->template = View::factory($this->template);
}
}
Creates a new controller instance. Each controller must be constructed with the request object that created it.
Request
$request
required - Request that created the controller Response
$response
required - The request's response void
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;
}
Executes the given action and calls the Controller::before and Controller::after methods.
Can also be used to catch exceptions from actions in a single place.
Response
public function execute()
{
// Execute the "before action" method
$this->before();
// Determine the action to use
$action = 'action_' . $this->request->action();
// If the action doesn't exist, it's a 404
if (!method_exists($this, $action)) {
throw HTTP_Exception::factory(404, 'The requested URL :uri was not found on this server.', [':uri' => $this->request->uri()])->request($this->request);
}
// Execute the action itself
$this->{$action}();
// Execute the "after action" method
$this->after();
// Return the response
return $this->response;
}
Issues a HTTP redirect.
Proxies to the HTTP::redirect method.
string
$uri
= string(0) "" - URI to redirect to int
$code
= integer 302 - HTTP Status code to use for the redirect public static function redirect($uri = '', $code = 302)
{
return HTTP::redirect((string) $uri, $code);
}
Checks the browser cache to see the response needs to be returned, execution will halt and a 304 Not Modified will be sent if the browser cache is up to date.
$this->check_cache(sha1($content));
string
$etag
= NULL - Resource Etag Response
protected function check_cache($etag = null)
{
return HTTP::check_cache($this->request, $this->response, $etag);
}