ZF-2879: Create an init() method for processing form models

Issue Type: Improvement Created: 2008-03-13T21:03:05.000+0000 Last Updated: 2008-03-21T17:34:14.000+0000 Status: Resolved Fix version(s): - 1.5.1 (25/Mar/08)

Reporter: Simon Mundy (peptolab) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:


Currently the documented best practice for creating a Zend_Form 'model' (i.e. adding fields/validators/etc. from within the user-defined class) is to override the '__construct' method.

The documentation fails to add the critical line 'parent::__construct($options)' - a sticking point that saw about an hours' worth of trying to debug the problem (that was my own fault, though :)

Instead of requiring '__construct' would it be possible to add an 'init()' method? The benefits are:-

  • Doesn't require overriding constructor (unnecessary in a lot of instances)
  • Becomes a recommended but not required coding practice within the framework - as per Zend_Db, Zend_Controller, etc...

Suggested patch:

<pre class="highlight">
Index: library/Zend/Form.php
--- library/Zend/Form.php   (revision 8819)
+++ library/Zend/Form.php   (working copy)
@@ -207,9 +207,22 @@
+        $this->init();
+     * Initialize object
+     *
+     * Called from {@link __construct()} as final step of object instantiation.
+     *
+     * @return void
+     */
+    public function init()
+    {
+    }
+    /**
      * Set form state from options array
      * @param  array $options 


Posted by Matthew Weier O'Phinney (matthew) on 2008-03-14T07:41:35.000+0000

Scheduling for 1.5.1.

One note: I think that init() should be called not as the last item in __construct(), but the last item before the call to loadDefaultDecorators(). This would allow you to prevent the default decorators from loading if you were to create them in your init() method.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-21T16:13:41.000+0000

Added in trunk and 1.5 release branch; docs updated in trunk.

Posted by Wil Sinclair (wil) on 2008-03-21T17:34:14.000+0000

I'm assuming this fix is merged to the 1.5 release branch for release with 1.5.1. Please update JIRA if this is not the case.

Have you found an issue?

See the Overview section for more details.


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

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