Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public MyFinalAction($userValue){
- // Object Model Erzeugen
- $dataObject = $this->objectManager->get('Tx_UserMyExtension_Domain_Model_MyModel');
- // Properties Setzen
- $dataObject->setPropertyOne($userValue);
- $dataObject->setPropertyTwo($dataBaseValue);
- // Validation
- $validatorResolver = $this->objectManager->get('Tx_Extbase_Validation_ValidatorResolver');
- $validatorConjunction = $validatorResolver->getBaseValidatorConjunction('Tx_UserKimAersignup_Domain_Model_KimSignup');
- $result = $validatorConjunction->isValid($dataObject);
- if($result === true){
- // Persist the New Object
- $this->dataObjectRepository->add($dataObject);
- }{
- // add a Custom Error Message for Frontend error Reporting
- $this->addCustomError('pseudoProperty','Model Validation has Failed',4711);
- // redirect to Error Action
- $this->errorAction();
- }
- }
- /**
- * Creates a Custom Error for Attributes wich are Evaluated in the Controller
- * @param string $propertyName name of the property with an error
- * @param string $message the default message if not Translated
- * @param integer $code the error code needs to be unique
- */
- protected function addCustomError($propertyName,$message,$code){
- $error = $this->objectManager->get('Tx_Extbase_MVC_Controller_ArgumentError', $propertyName);
- $propertyErrors = array();
- $propertyErrors[$propertyName] = $this->objectManager->get('Tx_Extbase_Validation_Error',$message,$code);
- $error->addErrors($propertyErrors);
- $this->propertyMapper->getMappingResults()->addError($error,$propertyName);
- $this->hasCustomError = true;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment