From 81e344d41877fb2f7f049d1c049adafcd425cac2 Mon Sep 17 00:00:00 2001 From: David Mintz Date: Thu, 12 Jan 2017 13:46:58 -0500 Subject: [PATCH 1/2] fix mistakes, suggest improvements in collections.md specifically, I have: - fixed references to Zend\Stdlib\Hydrator\ClassMethods - fixed a typo allws -> allows - suggested a line in the controller to set the form's action attribute to submit to itself rather setting it to the 'home' route in the viewscript - in the controller, wrapped the var_dump() in
 tags for legibility
- fixed a syntax error in the ProductFieldset getInputerFilterSpecification() (an array was opened with the old syntax but closed with the new)
- removed a line from the viewscript that gratuitously re-renders $this->formRow($product->get('name'));

As a side note, I was going to propose a revision to the part about not being able to submit the form with a Collection having fewer elements than it began with. I am not sure that's the case. The 'allow_remove' option seems to be just for that. But I haven't been able to prove it because at the moment I am struggling with my Doctrine and can't get it to remove entities from the N side of my 1:N.

Hope this helps :-)
---
 doc/book/collections.md | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/doc/book/collections.md b/doc/book/collections.md
index 1ec7f4bd..3a87263a 100644
--- a/doc/book/collections.md
+++ b/doc/book/collections.md
@@ -274,7 +274,7 @@ namespace Application\Form;
 use Application\Entity\Category;
 use Zend\Form\Fieldset;
 use Zend\InputFilter\InputFilterProviderInterface;
-use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
+use Zend\Hydrator\ClassMethods as ClassMethodsHydrator;
 
 class CategoryFieldset extends Fieldset implements InputFilterProviderInterface
 {
@@ -323,7 +323,7 @@ use Application\Entity\Product;
 use Zend\Form\Element;
 use Zend\Form\Fieldset;
 use Zend\InputFilter\InputFilterProviderInterface;
-use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
+use Zend\Hydrator\ClassMethods as ClassMethodsHydrator;
 
 class ProductFieldset extends Fieldset implements InputFilterProviderInterface
 {
@@ -392,7 +392,7 @@ class ProductFieldset extends Fieldset implements InputFilterProviderInterface
             'price' => [
                 'required' => true,
                 'validators' => [
-                    array(
+                    [
                         'name' => 'Float',
                     ],
                 ],
@@ -442,7 +442,7 @@ namespace Application\Form;
 use Zend\Form\Element;
 use Zend\Form\Form;
 use Zend\InputFilter\InputFilter;
-use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
+use Zend\Hydrator\ClassMethods as ClassMethodsHydrator;
 
 class CreateProduct extends Form
 {
@@ -502,13 +502,16 @@ Now, let's create a zend-mvc controller action:
      $form = new CreateProduct();
      $product = new Product();
      $form->bind($product);
-
      $request = $this->getRequest();
+     $form->setAttribute('action',$request->getRequestUri());
+     
      if ($request->isPost()) {
          $form->setData($request->getPost());
 
          if ($form->isValid()) {
-             var_dump($product);
+            echo '
';
+            var_dump($product);
+            echo '
'; } } @@ -530,7 +533,6 @@ And finally, the view: ```php setAttribute('action', $this->url('home')); $form->prepare(); echo $this->form()->openTag($form); @@ -547,7 +549,6 @@ echo $this->formCollection($product->get('categories')); $brand = $product->get('brand'); // Since the brand is a 1:1 relationship, its elements are rendered normally: -echo $this->formRow($product->get('name')); echo $this->formRow($brand->get('name')); echo $this->formRow($brand->get('url')); @@ -757,7 +758,7 @@ namespace Application\Form; use Zend\Form\Element; use Zend\Form\Form; use Zend\InputFilter\InputFilter; -use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator; +use Zend\Hydrator\ClassMethods as ClassMethodsHydrator; class CreateProduct extends Form { From f9ee24307a9425d9bfb8b60e8807654280466667 Mon Sep 17 00:00:00 2001 From: David Mintz Date: Fri, 13 Jan 2017 10:28:25 -0500 Subject: [PATCH 2/2] undo some edits per @froschdesign request --- doc/book/collections.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/book/collections.md b/doc/book/collections.md index 3a87263a..58e3abc9 100644 --- a/doc/book/collections.md +++ b/doc/book/collections.md @@ -503,15 +503,12 @@ Now, let's create a zend-mvc controller action: $product = new Product(); $form->bind($product); $request = $this->getRequest(); - $form->setAttribute('action',$request->getRequestUri()); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { - echo '
';
             var_dump($product);
-            echo '
'; } } @@ -533,8 +530,8 @@ And finally, the view: ```php setAttribute('action', $this->url('home')); $form->prepare(); - echo $this->form()->openTag($form); $product = $form->get('product');