簡體   English   中英

如何使用validationResover

[英]how to use validationResover

如此處所示我想使用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();
        }

    }
    ....
    ....
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM