[英]typo3 extbase: what happened to “forProperty” in a validator?
I have a model, lets call it Entry. 我有一个模型,我们称它为Entry。 And I created an EntryValidator to validate some fields. 我创建了EntryValidator来验证某些字段。 For example, the field "name" must not be empty. 例如,字段“名称”不能为空。 I can add an error like this: 我可以添加这样的错误:
public function isValid($entry) {
if(!$entry->getName() || trim($entry->getName()) == ''){
$this->addError('name must not be empty', 111);
}
}
but how can I assign this error to the field "name" ? 但是如何将这个错误分配给“名称”字段? I tried to google it and what I find over and over is this: 我试图用谷歌搜索,一遍又一遍地发现是这样的:
$this->result->forProperty('name')->addError($error);
But this doesn't work any more (I'm using typo3 6.2). 但是,这不再起作用了(我正在使用typo3 6.2)。 And I find to clues as to how to do this now. 我发现了有关如何立即执行此操作的线索。
Thanks! 谢谢!
you must add a return false and true to your isValid method. 您必须在isValid方法中添加return false和true。
public function isValid($entry) {
if(!$entry->getName() || trim($entry->getName()) == ''){
$this->addError('name must not be empty', 111);
return false;
}
return true;
}
or using with Error Object 或与错误对象一起使用
$this->result->forProperty('name')->addError(
new \TYPO3\CMS\Extbase\Error\Error(
$this->translateErrorMessage(
'key',
'ExtKey',
array()
),
111)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.