Ejemplo n.º 1
0
 public function indexAction()
 {
     $user = $this->identity();
     $em = $this->getServiceLocator()->get('Doctrine\\ORm\\EntityManager');
     $hydrator = new DoctrineObject($em, get_class($user));
     $data = $hydrator->extract($user);
     $form = new RegisterForm();
     $form->bind(new ArrayObject($data));
     return new ViewModel(['form' => $form]);
 }
Ejemplo n.º 2
0
 /**
  * display form to let user update some of profile data
  *
  * @return ViewModel
  */
 public function indexAction()
 {
     $form = new RegisterForm();
     $profileLayout = new ViewModel();
     $profileLayout->setTemplate('layout/profile');
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $user = $this->identity();
     $hydrate = new DoctrineObject($em, '\\Application\\Entity\\User');
     $userData = $hydrate->extract($user);
     $form->bind(new ArrayObject($userData));
     $this->actionView->setVariables(['form' => $form]);
     return $this->actionView;
 }
Ejemplo n.º 3
0
 public function editAction()
 {
     $viewModel = new ViewModel();
     if (!$this->getAuthService()->getIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $username = $this->getAuthService()->getIdentity()->getUserName();
     $registerForm = new RegisterForm();
     $registerForm->remove('captcha')->remove('password')->remove('re_password');
     $registerForm->get('submit')->setValue('修改資料');
     $registerForm->get('username')->setAttribute('readonly', true);
     $accountFilter = new AccountFIlter();
     $accountFilter->remove('password')->remove('re_password');
     $registerForm->setInputFilter($accountFilter);
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $user = $em->getRepository('Base\\Entity\\User')->findOneBy(array('username' => $username));
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $registerForm->setData($data);
         if ($registerForm->isValid()) {
             $user->setFirstName($registerForm->get('first_name')->getValue());
             $user->setLastName($registerForm->get('last_name')->getValue());
             //echo $registerForm->get('birthday')->getValue(); exit;
             $birthday = new \DateTime($registerForm->get('birthday')->getValue());
             $user->setBirthday($birthday);
             $user->setSex($registerForm->get('sex')->getValue());
             $user->setEmail($registerForm->get('email')->getValue());
             $em->persist($user);
             $em->flush();
             $this->flashMessenger()->addMessage('修改完成');
             $this->redirect()->toRoute('user/default', array('controller' => 'set', 'action' => 'edit'));
         }
     }
     $registerForm->bind($user);
     $viewModel->setVariable('form', $registerForm);
     return $viewModel;
 }