php - Fieldset validation data -
i have problem fieldsets in zf2, show problem.
here form (made angularjs, not zf2), can put name, , select if permit page or action (pages composed of actions).
the picture below partially show send zf2 :
here data model of customrole class :
class customrole { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @orm\column(type="string") */ protected $name; /** * @orm\onetomany(targetentity="app\entity\users\customrolepagepermission", mappedby="customrole") */ protected $pagepermissions; /** * @orm\onetomany(targetentity="app\entity\users\customroleactionpermission", mappedby="customrole") */ protected $actionpermissions; /** * @orm\manytoone(targetentity="app\entity\users\globalrole") */ protected $globalrole; /** * @orm\manytoone(targetentity="app\entity\cie", inversedby="customroles") * @orm\joincolumn(name="cie", referencedcolumnname="id_cie") */ protected $cie; /** * @orm\onetomany(targetentity="app\entity\users\user", mappedby="customrole") */ protected $users; ...
here class customrolepagepermission (which near same customroleactionpermission) :
class customrolepagepermission extends pagepermission { /** * @orm\id * @orm\manytoone(targetentity="app\entity\users\customrole", inversedby="pagepermissions") * @orm\joincolumn(name="custom_role_id", referencedcolumnname="id", nullable=false) */ protected $customrole; ...
and abstract class pagepermission :
abstract class pagepermission { /** * @orm\id * @orm\manytoone(targetentity="app\entity\page") * @orm\joincolumn(name="page_id", referencedcolumnname="id", nullable=false) */ protected $page; /** * @orm\column(type="boolean") */ protected $permission; ...
now fieldset corresponding customrole class (i have made on each entities) :
class customrolefieldset extends fieldset implements inputfilterproviderinterface { protected $servicelocator; public function __construct(entitymanager $entitymanager) { parent::__construct('role'); $this->sethydrator(new doctrinehydrator($entitymanager, 'app\entity\users\customrole')) ->setobject(new customrole()); $this->add(array('name' => 'name')); $customrolepagepermissionfieldset = new customrolepagepermissionfieldset($entitymanager); $this->add(array( 'type' => 'zend\form\element\collection', 'name' => 'pagepermission', 'options' => array( 'target_element' => $customrolepagepermissionfieldset ), )); $customroleactionpermissionfieldset = new customroleactionpermissionfieldset($entitymanager); $this->add(array( 'type' => 'zend\form\element\collection', 'name' => 'actionpermission', 'options' => array( 'target_element' => $customroleactionpermissionfieldset ), )); } public function getinputfilterspecification() { return array( 'name' => array('required' => true), 'pagepermission' => array('required' => true), 'actionpermission' => array('required' => true), ); } } ...
here fieldset customrolepagepermissionfieldset :
class customrolepagepermissionfieldset extends fieldset implements inputfilterproviderinterface { protected $servicemanager; public function __construct(entitymanager $entitymanager) { parent::__construct(); $this->sethydrator(new doctrinehydrator($entitymanager, 'app\entity\users\customrolepagepermission')) ->setobject(new customrolepagepermission()); $this->add(array('name' => 'permission')); } ...
and then, controller :
... $customroleform = new customroleform($em); $customrole = new customrole(); $formdata = $request->getpost(); $customroleform->bind($customrole); $customroleform->setdata($formdata); if ($customroleform->isvalid()) { $customrole->setcie($cie); $customrole->setglobalrole($globalrole); $em->persist($customrole); $em->flush(); return $this->ok($customrole->getid()); } ...
problem
when send form, customrole created, pages , actions checked not linked customrole created, if had never checked checkbox.
i don't understand why doesn't have effects, have ideas ?
thanks lot in advance ! :)
your collection should "pagepermissions" hydrator call setpagepermissions.
Comments
Post a Comment