Пример #1
0
 public function addAction()
 {
     $form = new OenologistForm();
     $form->get('submit')->setValue('Add');
     //Populate Country DropDown
     $idcountryOptions = array();
     foreach ($this->getCountrySelectData() as $country) {
         $idcountryOptions[$country->getIdcountry()] = $country->getName();
     }
     $form->get('idcountry')->setAttribute('options', $idcountryOptions);
     // CSS
     $form->get('firstname')->setAttribute('class', 'form-control');
     $form->get('firstname')->setAttribute('placeholder', 'Ej.: Manuel');
     $form->get('lastname')->setAttribute('class', 'form-control');
     $form->get('lastname')->setAttribute('placeholder', 'Ej.: Vivar');
     $form->get('idcountry')->setAttribute('class', 'form-control');
     $form->get('genre')->setAttribute('class', 'form-control');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $person = new Person();
         $oenologist = new Oenologist();
         $form->setInputFilter($person->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //Save Person first
             $person->exchangeArray($form->getData());
             $person->setIdcountry($this->getEntityManager()->find('Application\\Entity\\Country', $request->getPost('idcountry')));
             $this->getEntityManager()->persist($person);
             $this->getEntityManager()->flush();
             //Save Oenologist then
             $oenologist->setDisabled($request->getPost('disabled'));
             $oenologist->setIdperson($person);
             $this->getEntityManager()->persist($oenologist);
             $this->getEntityManager()->flush();
             // Redirect to Country List
             return $this->redirect()->toRoute('oenologist');
         }
     }
     return array('form' => $form);
 }
 /**
  * {@inheritDoc}
  */
 public function setIdcountry(\Application\Entity\Country $idcountry = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setIdcountry', array($idcountry));
     return parent::setIdcountry($idcountry);
 }