コード例 #1
0
 public function editAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $viewmodel = new ViewModel();
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('student', array('controller' => 'student', 'action' => 'add'));
     }
     $student = $entityManager->find('Admin\\Entity\\Student', $id);
     if (!$student) {
         return $this->redirect()->toRoute('student', array('controller' => 'student', 'action' => 'index'));
     }
     $form = new StudentForm($entityManager);
     // $form->setHydrator (new DoctrineEntity($entityManager,'Admin\Entity\Subject'));
     $form->bind($student);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($dataForm);
         if ($form->isValid()) {
             $pre = $form->getData('student');
             $student->setCurrentclass($pre->getClass());
             $entityManager->persist($student);
             $entityManager->flush();
             //
             // Redirect to list of albums
             return $this->redirect()->toRoute('student', array('controller' => 'student', 'action' => 'index'));
         }
     }
     $viewmodel->setVariables(array('form' => $form, 'id' => $id));
     return $viewmodel;
 }
コード例 #2
0
 public function editAction()
 {
     $entityManager = $this->getOM();
     $viewmodel = new ViewModel();
     $ud = $this->zfcUserAuthentication()->getIdentity()->getId();
     $iud = $this->getOM()->getRepository('Admin\\Entity\\Student')->findOneBy(array('user' => $ud));
     $id = $iud->getId();
     if (!$id) {
         return $this->redirect()->toRoute('students', array('controller' => 'students', 'action' => 'dashboard'));
     }
     $student = $entityManager->find('Admin\\Entity\\Student', $id);
     $image = $student->getImage();
     if (!$student) {
         return $this->redirect()->toRoute('students', array('controller' => 'students', 'action' => 'dashboard'));
     }
     $form = new StudentForm($entityManager);
     $form->bind($student);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($dataForm);
         //exclude section and year from being validated
         $form->setValidationGroup(array('student' => array('image', 'person' => array('fname', 'lname', 'mname', 'mobile', 'address', 'country', 'state', 'lga', 'dob', 'sex', 'religion', 'nokName', 'nokRel', 'nokMobile'))));
         if ($form->isValid()) {
             $pre = $form->getData('student');
             $data = $pre->getImage();
             if (!$data) {
                 $student->setImage($image);
             }
             $student->setCurrentclass($pre->getClass());
             $entityManager->persist($student);
             $entityManager->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('students', array('controller' => 'students', 'action' => 'dashboard'));
         }
     }
     $viewmodel->setVariables(array('form' => $form, 'id' => $id, 'image' => $image));
     return $viewmodel;
 }