如何使用 validationResover

how to use validationResover

如图所示here 我想使用 validationResolver 动态验证我应用程序中的用户输入。因此,我想证明我的控制器中的条件是否为真。如果条件为真,我想用自己的验证器来验证。

为此我试过了:

public function createAction(Object $newObject) { 
    $TS = $newObject->getSomeProperty();
    $ABT = $newObject->getSomeOtherProperty();
    if ($TS === 'specialvalue') {
          $validatorResolver->createValidator('Your.Package:Foo'));
    }

但我得到(当然)500 异常:

#1: Notice: Undefined variable: validatorResolver in /var/www...

请提示如何使用 $validatorResolver。

我现在是这样做的:

public function createAction(Object $newObject) {
    $TS = $newObject->getSomeProperty();
    $ABT = $newObject->getSomeOtherProperty();
    if ($ABT === 'specialvalue') {
        $validatorResolver = new \TYPO3\Flow\Validation\ValidatorResolver();
        $customValidator = $validatorResolver->createValidator('Your.Package:Foo');
        $result = $customValidator->validate($TS);

        if ($result->hasErrors()) {
             $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Here you can type in the error message!'));
            $this->errorAction()->forwardToReferringRequest();
        }

    }
    ....
    ....
}