2014-11-16 5 views
1

Typo3 흐름의 유효성 검사에 문제가 있습니다.Typo3 흐름 유효성 검사 오류

내가 REST에 대한 POST 요청을하고 있는데, 컨트롤러에 대한 조치입니다.

/** 
    * Create Customer 
    * 
    * 
    * @param int $clientId 
    * @param string $name 
    * @param string $phone 
    * @param string $mail 
    * @param string $zip 
    * @param string $city 
    * @param int countryId 
    * @return string 
    */ 
    public function createAction($clientId, $name, $phone, $mail, $zip, $city, $countryId) { 
     try{ 
      $this->checkAccessArgs(); 
      $client = $this->clientCustomerRepository->getReference('\Shopbox\API\Domain\Model\Client',$clientId); 
      $country = $this->clientCustomerRepository->getReference('\Shopbox\API\Domain\Model\Country',$countryId); 
      $newCustomer = new ClientCustomer(); 
      $newCustomer->setClient($client); 
      $newCustomer->setCountry($country); 
      $newCustomer->setName($name); 
      $newCustomer->setPhone($phone); 
      $newCustomer->setMail($mail); 
      $newCustomer->setZip($zip); 
      $newCustomer->setCity($city); 
      $newCustomer->setCrdate(time()); 
      $newCustomer->setTstamp(time()); 
      $newCustomer->setDeleted(0); 
      $newCustomer->setHidden(0); 
      $customerValidator = $this->validatorResolver->getBaseValidatorConjunction('\Shopbox\API\Domain\Model\ClientCustomer'); 
      $result = $customerValidator->validate($newCustomer); 
      if($result->hasErrors()){ 
       throw new \Exception($result->getFirstError()->getMessage() ,$result->getFirstError()->getCode()); 
      } 
      $this->clientCustomerRepository->add($newCustomer); 
      $this->persistenceManager->persistAll(); 
      $this->response->setStatus(201); 
      $this->view->setVariablesToRender(array(self::JSON_RESPONSE_ROOT_SINGLE)); 
      $this->view->assign(self::JSON_RESPONSE_ROOT_SINGLE, 
       array(self::JSON_RESPONSE_ROOT_SINGLE=> $newCustomer) 
      ); 
     } 
     catch(\Exception $e){ 
      $this->response->setStatus($e->getCode()); 
      return $this->assignError($e->getMessage()); 
     } 
    } 

이것은 모델에서 유효성을 검사하는 방법입니다.

/** 
    * @var string 
    * @Flow\Validate(type="EmailAddress") 
    */ 
    protected $mail; 

    /** 
    * @var string 
    * @Flow\Validate(type="StringLength", options={ "minimum"=8, "maximum"=8 }) 
    */ 
    protected $phone; 

오류가 발생했습니다. 나는 액션 함수 내에서 유효성 검사를 넣지 않으면

Fatal error: Call to a member function getMessage() on a non-object in /path_to_project/flow2/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/path_to_Controller.php on line 87

는 내가 확인 메시지가하지만 그것을하지 말아야 할 무엇을 데이터베이스에 저장합니다.

답변

0
if ($result->hasErrors()) { 

적어도 하나의 속성에 오류가 있습니다 (부모에게 알림) 오류가 발생하여 개체에 오류가 발생했습니다.

하지만 .. 부모는 자신의 오류를 배열에 저장하지 않습니다 - 속성 않습니다 - 그래서 .. $result->getErrors()$result->getFirstError() 같은 비어 ..

속성 오류에 대한 부모의 액세스를 얻으려면 당신이 사용할 수 있습니다

$errors = $result->getFlattenedErrors(); 

또는

$result->forProperty('name')->getFirstError();