Warning! This page has the following tags:

  • This page needs to be merged with docbook documentation.

Output Types

Agavi's Output Types allow you to serve multiple versions of the same Action, using the same View, but separate templates and probably different Renderers.

In the View, you set a template without the file extension, so if you have a PHP template called "IndexSuccess?.php" for the IndexSuccessView?, you do $this->setTemplate('IndexSuccess'); in the View (same for Decorator templates).

Choosing Output Types

There are many ways to select an Output Type. For instance, you could write a Filter that checks if there's a variable called print in the URL, and, if yes, set the Output Type to "html_print" using $controller-setOutputType('html_print');. Or you could decide which Output Type to use in the View, which makes sense if you want to use it only for a few Actions. Or, probably the best option, you just use the Routing to tell Agavi which Output Type to use, that's the most convenient option. Just be sure not to put the necessary logic into an Action, because stuff like that just doesn't belong there.

Configuring Output Types

To learn about the Output Type configuration, please read ConfigurationFiles/OutputTypesDotXml.

Advanced Use

You can also manually force the use of a specific Renderer by returning an instance from the View. Agavi will then ignore the defined Renderer for the current Output Type and use your one instead. It's basically just three lines of code:

$renderer = new MyCustomPdfRenderer();
$renderer->setView($this);
$renderer->setExtension('.pdf.php'); // if you want to override the one that's defined in MyCustomPdfRenderer
return $renderer;

If you don't return anything (i.e. return value of View::execute() is null, Agavi will proceed as usual.