2014-11-16 5 views
1

У меня проблема с проверкой в ​​потоке Typo3.Ошибка проверки потока Typo3

Я выполняю запрос POST для REST, и это действие для контроллера.

/** 
    * 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(); 
Смежные вопросы