示例#1
0
 public function testBindFromProfileWillPopulateDataFromProfileEntity()
 {
     $profileRaw = ['id' => 1, 'fullname' => "Trinh Thanh Tam", 'dob' => '2018-06-18', 'email' => '*****@*****.**'];
     $profile = new Application_Model_Profile(['data' => $profileRaw]);
     $this->form->bindFromProfile($profile);
     $this->assertEquals($profileRaw, $this->form->getValues());
 }
 /**
  * Edit existed profile
  *
  * Handler GET, POST request
  * @link GET /profile/edit/:id display form profile populated
  * @link POST /profile/edit persit profile
  *
  */
 public function editAction()
 {
     $profileRepoFactory = new Application_Factory_ProfileRepository();
     $profileModelFactory = new Application_Factory_ProfileModel();
     $profileForm = new Application_Form_Profile(['id' => 'edit-profile']);
     $profileForm->submit->setLabel("Save");
     $profileRepo = $profileRepoFactory->createService();
     $this->view->profileForm = $profileForm;
     //GET request handler
     $visitEditProfilePage = !$this->getRequest()->isPost();
     if ($visitEditProfilePage) {
         $profileId = (int) $this->getParam('id', 0);
         $profileEntity = $profileRepo->findById($profileId);
         $profileForm->bindFromProfile($profileEntity);
         return;
         //render edit profile form
     }
     //POST request handler
     $postInvalidProfile = !$profileForm->isValid($this->getRequest()->getPost());
     if ($postInvalidProfile) {
         return;
         //represent profile form with error messages
     }
     //Persit filtered profile to persistent
     $profileRepo->save($profileModelFactory->createService($profileForm->getValues()));
     $this->_helper->redirector('index', 'profile', 'default');
 }