Writing a custom view strategy/renderer
Nothing is more exciting in coding than developing your own bits of custom features that integrate with the framework. In this recipe we will be discussing how to create our own XML view strategy. We will show you how to simply create the basis for a new strategy without too much of a bother.
How to do it…
Sometimes the default strategies and renderers provided are not enough for a specific situation, so let's talk through on how to create our own view strategy/renderer.
Creating the XmlOutput renderer
Let us see first on how our renderer would look like, as that is possibly one of the laziest classes we will ever code. We will do this in a new class located in /module/XmlOutput/src/XmlOutput/View/Renderer/XmlRenderer.php
.
<?php namespace XmlOutput\View\Renderer; use Zend\View\Renderer\PhpRenderer; /** * This is the XML Renderer, which is as you can see * empty as we don't really need * to do anything to get this one going, the PhpRenderer *...