[TYPO3-mvc] yes, nested objects validation is a missing feature at current extbase version (1.3)
Alisha
mail at alisha-huber.de
Thu Oct 20 23:03:30 CEST 2011
I have a class Tx_xx_Domain_Validator_CoupleValidator
as described by you. I do not know what I must do even more.
in my update action I use:
@validate $couple Tx_xx_Domain_Validator_CoupleValidator
But how do I get the errors?
in the update action I tried:
$errors = $this->errors();
$errors = $this->request->getErrors();
if($errors){
foreach ($errors as $error){
foreach($error->getErrors() as $e) {
$this->flashMessages->add($e->getMessage());
}}}
but it do not work ..
the only error : An error occurred while trying to call
Tx_xx_Controller_CoupleController->updateAction()
Regards
Alisha
Couple has a 1:1 relation zu appM
my validator-class:
class Tx_Dancestudio_Domain_Validator_CoupleValidator extends
Tx_Extbase_Validation_Validator_AbstractValidator {
/**
* @var $objectManager Tx_Extbase_Object_ObjectManager
*/
protected $objectManager;
public function injectObjectManager(Tx_Extbase_Object_ObjectManager
$objMgr) {
$this->objectManager = $objMgr;
}
/**
* Checks if the given value is valid according to the validator.
*
* If at least one error occurred, the result is FALSE and any
errors can
* be retrieved through the getErrors() method.
*
* Note that all implementations of this method should set
$this->errors() to an
* empty array before validating.
*
* @param mixed $value The value that should be validated
* @return boolean TRUE if the value is valid, FALSE if an error
occured
*/
public function isValid($value) {
if(!is_object($value) || !$value instanceof
Tx_Dancestudio_Domain_Model_Couple) {
return FALSE;
}
$appMValidator =
$this->objectManager->get('Tx_Extbase_Validation_ValidatorResolver')->getBaseValidatorConjunction('Tx_Dancestudio_Domain_Model_Application');
if (!$appMValidator->isValid($value->getAppM())) {
$this->errors[] = $this->createPropertyError('appM',
$appMValidator->getErrors());
}
return count($this->errors) == 0;
}
/**
* @param string $propertyName
* @param array $errors
* @return Tx_Extbase_Validation_PropertyError
*/
protected function createPropertyError($propertyName, array $errors) {
$error = new Tx_Extbase_Validation_PropertyError($propertyName);
$error->addErrors($errors);
return $error;
}
}
More information about the TYPO3-project-typo3v4mvc
mailing list