PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Custom View Objects

Zend_Layout allows you to use any class implementing Zend_View_Interface or extending Zend_View_Abstract for rendering your layout script. Simply pass in your custom view object as a parameter to the constructor/startMvc(), or set it using the setView() accessor:

<?php
$view 
= new My_Custom_View();
$layout->setView($view);

Not all Zend_View implementations are equal

While Zend_Layout allows you to use any class implementing Zend_View_Interface, you may run into issues if they can not utilize the various Zend_View helpers, particularly the layout and placeholder helpers. This is because Zend_Layout makes variables set in the object available via itself and placeholders.

If you need to use a custom Zend_View implementation that does not support these helpers, you will need to find a way to get the layout variables to the view. This can be done by either extending the Zend_Layout object and altering the render() method to pass variables to the view, or creating your own plugin class that passes them prior to rendering the layout.

Alternately, if your view implementation supports any sort of plugin capability, you can access the variables via the 'Zend_Layout' placeholder, using the placeholder helper:

<?php
$placeholders 
= new Zend_View_Helper_Placeholder();
$layoutVars   $placeholders->placeholder('Zend_Layout')->getArrayCopy();

Zend Framework