The View class interacts with a variety of other classes in order to achieve maximum
flexibility and configurability at all points in the view rendering and presentation
process. The Loader class is tasked with locating and reading template files which are then
passed to the Renderer adapter subclass.
In the default configuration, the File adapter acts as both renderer and loader, loading files
from paths defined in _process steps_ (described below) and rendering them as plain PHP files,
augmented with special syntax.
The View class operates on _processes_, which define the steps to render a completed view. For
example, the default process, which renders a template wrapped in a layout, is comprised of two
_steps_: the first step renders the main template and captures it to the rendering context, where
it is embedded in the layout in the second step. See the $_steps and $_processes properties
for more information.
Using steps and processes, you can create rendering scenarios to suit very complex needs.
By default, the View class is called during the course of the framework's dispatch cycle by the
Media class. However, it is also possible to instantiate and call View directly, in cases
where you wish to bypass all other parts of the framework and simply return rendered content.
A simple example, using the Simple renderer/loader for string templates:
{{{
$view = new View(array('loader' => 'Simple', 'renderer' => 'Simple'));
echo $view->render('element', array('name' => "Robert"), array('element' => 'Hello, {:name}!'));
Output:
"Hello, Robert!";
}}}
_Note_: This is easily adapted for XML templating.
Another example, this time of something that could be used in an appliation
error handler:
{{{
$view = new View(array(
'paths' => array(
'template' => '{:library}/views/errors/{:template}.{:type}.php',
'layout' => '{:library}/views/layouts/{:layout}.{:type}.php',
)
));
$page = $View->render('all', array('content' => $info), array(
'template' => '404',
'layout' => 'error'
));
}}}
To learn more about processes and process steps, see the $_processes and $_steps properties,
respectively.