Skip to content

Commit

Permalink
Fix the problem of bind() throwing exception
Browse files Browse the repository at this point in the history
This commit modifies the IndexController to test the really needed behavior: $form->bind()

The problem: $form->bind() method was throwing an unespected exception.
This problem was introduced in ZF 2.2.5 through zendframework/zendframework#5093

So the fatest solution would be downgrade to ZF 2.2.4, then lets make it :D
  • Loading branch information
danizord committed Dec 12, 2013
1 parent e12efa6 commit dcc5a0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"require": {
"zendframework/zendframework": "2.2.*",
"zendframework/zendframework": "2.2.4",
"doctrine/doctrine-module": "~0.8@beta",
"doctrine/doctrine-orm-module": "~0.8@beta"
}
Expand Down
53 changes: 23 additions & 30 deletions src/FhcsFormTest/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace FhcsFormTest\Controller;

use FhcsFormTest\Entity\Freight;
use FhcsFormTest\Entity\Order;
use FhcsFormTest\Entity\Product;
use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController {
Expand All @@ -19,36 +22,26 @@ public function setFormElementManager($formElementManager) {
public function indexAction() {
$form = $this->getFormElementManager()->get('FhcsFormTest\Form\SomeForm');

$data = array(
'order' => array(
'freights' => array(
array(
'products' => array(
array('name' => 'product 1'),
),
),
array(
'products' => array(
array('name' => 'product 2'),
array('name' => 'product 3'),
),
),
array(
'products' => array(
array('name' => 'product 4'),
array('name' => 'product 5'),
array('name' => 'product 6'),
),
),
),
),
);

$form->setData($data);
$form->isValid();

// Returns a validated, filtered and hydrated instance of FhcsFormTest\Entity\Order ;)
var_dump($form->getData());
$freight1 = new Freight;
$freight2 = new Freight;
$freight3 = new Freight;

$freight1->addProduct(new Product('Product 1'));

$freight2->addProduct(new Product('Product 2'));
$freight2->addProduct(new Product('Product 3'));

$freight3->addProduct(new Product('Product 4'));
$freight3->addProduct(new Product('Product 5'));
$freight3->addProduct(new Product('Product 6'));

$order = new Order;

$order->addFreight($freight1);
$order->addFreight($freight2);
$order->addFreight($freight3);

$form->bind($order);

return array('form' => $form);
}
Expand Down

0 comments on commit dcc5a0b

Please # to comment.