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

Issue Type: Improvement Created: 2010-07-13T19:27:34.000+0000 Last Updated: 2010-11-22T15:15:53.000+0000 Status: Resolved Fix version(s): - 1.11.1 (30/Nov/10)

Reporter: Mark Maynereid (mim) Assignee: Richard Tuin (richardtuin) Tags: - Zend_Form

Related issues: Attachments: - ZF-10149-rtuin-v2.patch


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():

<pre class="highlight">
    public function setOptions(array $options)
        if (isset($options['view'])) {


Posted by Richard Tuin (richardtuin) on 2010-11-19T13:26:22.000+0000

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

Posted by Mark Maynereid (mim) on 2010-11-19T19:25:07.000+0000

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

Posted by Richard Tuin (richardtuin) on 2010-11-20T03:26:51.000+0000

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.

Posted by Mark Maynereid (mim) on 2010-11-20T04:12:03.000+0000

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

Posted by Richard Tuin (richardtuin) on 2010-11-20T04:13:13.000+0000

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.

Posted by Mark Maynereid (mim) on 2010-11-20T04:17:44.000+0000

Appreciated, thanks.

Posted by Richard Tuin (richardtuin) on 2010-11-20T05:01:37.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.