我想验证TYPO3中的文件输入字段,但似乎NotEmpty annonation不适用于filereference类型的属性:
/**
* image
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* @validate NotEmpty
*/
protected $image;
/**
* Returns the image
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage() {
return $this->image;
}
/**
* Sets the image
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* @return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
$this->image = $image;
}
这个简单的流体标记:
<f:render partial="FormErrors" arguments="{field: 'data.image'}" />
<f:form.upload property="image" />
因此,如果尝试提交空上传表单,我会收到以下错误消息,因为filereference仍然为null:
Exception while property mapping at property path "":PHP Catchable Fatal Error: Argument 1 passed to Fox\Example\Domain\Model\Data::setImage() must be an instance of TYPO3\CMS\Extbase\Domain\Model\FileReference, null given...
1 回答
好吧,我的模型设置器中的图像属性出错了:O ...就像pgampe说的,如果你遇到fileupload的问题,请看看这个很棒的例子:github.com/helhum/upload_example如果你想添加验证上传输入只是为图像属性添加一个验证注释,它就像一个魅力:)
我改变了:
至