Example #1
0
 public function editAction()
 {
     if ($this->request->isPost()) {
         $id = (int) $this->identity()->id;
         if (!$id) {
             return $this->redirect()->toRoute('home');
         }
         try {
             $user = $this->getObjectManager()->getRepository('Application\\Entity\\User')->find($id);
         } catch (\Exception $ex) {
             return $this->redirect()->toRoute('home');
         }
         $form = new UserForm($this->getObjectManager());
         $form->bind($user);
         $form->setData($this->request->getPost());
         if ($form->isValid()) {
             $this->getObjectManager()->persist($user);
             $this->getObjectManager()->flush();
             return $this->redirect()->toRoute('user');
         }
     }
     return $this->redirect()->toRoute('user');
 }
Example #2
0
 public function editAction()
 {
     $userId = $this->params('id');
     $request = $this->getRequest();
     $viewmodel = new ViewModel();
     $sl = $this->getServiceLocator();
     $roleTable = $sl->get('Backend\\Model\\RoleTable');
     $userTable = $sl->get('Backend\\Model\\UserTable');
     $form = new UserForm($roleTable);
     if ($request->isPost()) {
         // @TODO addfilters
         //$form->setInputFilter($filters);
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             unset($data['submit']);
             $dataId = array('id' => $userId);
             $userTable->editUser($data, $dataId);
         }
     } else {
         $userData = $userTable->getUser($userId);
         foreach ($userData as $user) {
             $form->get('username')->setValue($user['username']);
             $form->get('email')->setValue($user['email']);
             $form->get('role_id')->setValue($user['role_id']);
         }
     }
     $viewmodel->form = $form;
     return $viewmodel;
 }