[TYPO3-mvc] Extbase 1.3 Model Validation In Controller

chris Wolff chris at connye.com
Thu Aug 8 10:49:51 CEST 2013


Hi Jan,
hier meine Beispielhafte Lösung (im Controller)
für bessere lesbarkeit habe ich sie auch mal auf pastebin gestellt:
http://pastebin.com/zLsmeVGg


public MyFinalAction($userValue){
// Object 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;
}


gruss chris

Am 8. August 2013 09:42 schrieb Jan Kornblum <jan.kornblum at gmx.de>:
> Hi Chris,
>
>
>> Danke für deine Mail das werde ich gleich ausprobieren.
>
>
> Post doch dann mal wie du es dann letztendlich gelöst hast (auszugsweise),
> würde mich nämlich auch interessieren!
>
> Grüße, Jan
>
>
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



-- 
christian wolff - webdeveloper, tech-loving geek and typo3 enthusiast
telefon: +49 30 347 244 88
mobil:  +49 179 49 44 758
email: chris at connye.com
adresse: friedelstraße 31 - 12047 berlin

xing-profil: http://www.xing.com/profile/Christian_Wolff43
google+: https://plus.google.com/u/0/115669673917212236875/posts?hl=de
facebook: https://www.facebook.com/1stMachine
flattr: https://flattr.com/profile/1stmachine


More information about the TYPO3-project-typo3v4mvc mailing list