ZF-10149: "view" option assigned too late on instantiating Zend_Form


Passing an alternative view object meeting Zend_View_Interface via the options array in Zend_Form constructor fails with:

ViewHelper decorator cannot render without a registered view object at /home/lib/ZendFramework-1.10.6/library/Zend/Form/Decorator/ViewHelper.php (226).

Seems that setView is happening too late in setOptions().

Solution I found was to insert this code at the top of setOptions():

    public function setOptions(array $options)
        if (isset($options['view'])) {


Can you please provide some additional information on how to reproduce this issue?

class My_View implements Zend_View_Interface {...}
$form = new Zend_Form(array('view' => new My_View()));

The setOptions method in Zend_Form does not enable the user to pass a view object in the array. In fact, it explicitly ignores the view object.

Zend_Form::setView needs to be called explicitly to use the custom implementation of Zend_View_Interface.

I missed the $forbidden array. My mistake. Apols.

Although originally this issue references to expected behavior, allowing the user to add a view object using the options array is a good suggestion.

I have made a patch for it, and included the associated unit tests.

Appreciated, thanks.

Suggestion from FreeaqMob on irc was to improve the unit test to test on type safety.

Updated the unit test and uploaded the new patch.