O'Reilly logo

Zend Framework 2 Cookbook by Josephus Callaars

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using view strategies/renderers

Normally we will use the View to output HTML, but sometimes we want a more diverse way of outputting for example JSON or XML. This recipe will provide us with enough information to accomplish this easily.

Getting ready

We simply require the Zend Framework 2 skeleton application to get us going with this recipe. Nothing exotic is required.

How to do it…

Using different view strategies and renderers is a common practice in an application. In this recipe we'll explain how to do that.

Adding a view strategy

We can easily add a view strategy to our application by simply appending the view_manager configuration in the module configuration file (/module/Restful/config/module.config.php) as shown as follows:

<?php return array( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required