Guest User

Untitled

a guest
Aug 8th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. public MyFinalAction($userValue){
  4.     // Object Model Erzeugen
  5.     $dataObject = $this->objectManager->get('Tx_UserMyExtension_Domain_Model_MyModel');
  6.  
  7.     // Properties Setzen
  8.     $dataObject->setPropertyOne($userValue);
  9.     $dataObject->setPropertyTwo($dataBaseValue);
  10.  
  11.     // Validation
  12.     $validatorResolver = $this->objectManager->get('Tx_Extbase_Validation_ValidatorResolver');
  13.     $validatorConjunction = $validatorResolver->getBaseValidatorConjunction('Tx_UserKimAersignup_Domain_Model_KimSignup');
  14.     $result = $validatorConjunction->isValid($dataObject);
  15.     if($result === true){
  16.         // Persist the New Object
  17.         $this->dataObjectRepository->add($dataObject);
  18.     }{
  19.         // add a Custom Error Message for Frontend error Reporting
  20.         $this->addCustomError('pseudoProperty','Model Validation has Failed',4711);
  21.         // redirect to Error Action
  22.         $this->errorAction();
  23.     }
  24.  
  25. }
  26.  
  27. /**
  28.  * Creates a Custom Error for Attributes wich are Evaluated in the Controller
  29.  * @param string $propertyName name of the property with an error
  30.  * @param string $message      the default message if not Translated
  31.  * @param integer $code        the error code needs to be unique
  32.  */
  33. protected function addCustomError($propertyName,$message,$code){
  34.     $error = $this->objectManager->get('Tx_Extbase_MVC_Controller_ArgumentError', $propertyName);
  35.     $propertyErrors = array();
  36.     $propertyErrors[$propertyName] = $this->objectManager->get('Tx_Extbase_Validation_Error',$message,$code);
  37.     $error->addErrors($propertyErrors);
  38.     $this->propertyMapper->getMappingResults()->addError($error,$propertyName);
  39.     $this->hasCustomError = true;
  40. }
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment