Views have two fundamental jobs:
Tell an IPolicy whether or not the view
can respond with the Response object returned
from a Controller.
Respond using the state in a Response
object by sending headers
(AbstractView::sendHeadersFor())
and rendering the response
(AbstractView::render()).
AbstractView is the abstract base class of all views in Recess. It's two abstract methods are of interest to View developers:
canRespondWith(Response
$response) - Returns a boolean indicating whether the
View can respond with $response. It is the view's job to check the
requested mime-type/format
$response->request->accepts->format(). Responding true
implies that the view can render the response in the format
requested.
render(Response
$response) - Using the data in $response, render a
response in the desired format.
NativeView (!RespondsWith
Native) is a simple View implementation that takes a response
and maps it to a template. This mapping is done based on the requested
format, so if a controller returns $this->ok('viewTemplate') and the requested
format is JSON, then NativeView will look for
'viewTemplate.json.php'.
NativeView loads no helpers and is as close to
native PHP templates as you can get in Recess.
NativeView does not load any helpers by
default.
As already aluded to, NativeView will select a template based on the requested format. In Recess, a format can be requested in one of two ways: 1) It can be forced by appending the format to the end of a URL, i.e. /foo/bar.json, 2) It can be negotiated using the Accept HTTP header. In the first case Recess will only look for a "*.json.php" template.
LayoutsView (!RespondsWith
Layouts) extends from NativeView but
auto-loads key helpers and initializes the Layout
helper. This is the default View for Recess applications. The helpers
available in templates loaded from LayoutsView
are: Html, Url,
Layout, Buffer, and
Part. Your templates are rendered using the
Layout helper's draw
method.