History | Log In     View a printable version of the current page.  

Welcome to our new server and updated tools!



Issue Details (XML | Word | Printable)

Key: ZF-2879
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Matthew Weier O'Phinney
Reporter: Simon Mundy
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Create an init() method for processing form models

Created: 13/Mar/08 09:03 PM   Updated: 21/Mar/08 05:34 PM  Due: 20/Mar/08
Component/s: Zend_Form
Affects Version/s: 1.5.0RC1
Fix Version/s: 1.5.1

Time Tracking:
Original Estimate: 15 minutes
Original Estimate - 15 minutes
Remaining Estimate: 15 minutes
Remaining Estimate - 15 minutes
Time Spent: Not Specified
Remaining Estimate - 15 minutes

Fix Version Priority: Should Have


 Description  « Hide
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:

Index: library/Zend/Form.php
===================================================================
--- library/Zend/Form.php	(revision 8819)
+++ library/Zend/Form.php	(working copy)
@@ -207,9 +207,22 @@
         }
 
         $this->loadDefaultDecorators();
+
+        $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


 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Matthew Weier O'Phinney - 14/Mar/08 07:41 AM
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.


Matthew Weier O'Phinney - 21/Mar/08 04:13 PM
Added in trunk and 1.5 release branch; docs updated in trunk.

Wil Sinclair - 21/Mar/08 05:34 PM
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.