0

如此处所示我想使用 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。

4

1 回答 1

0

我现在这样做了:

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();
        }

    }
    ....
    ....
}
于 2015-06-17T05:25:48.470 回答