Validation 模型中关系属性的类型3验证
我的extbase扩展中有一个模型,如下所示。 默认情况下,Type3将递归验证所有作者的属性及其关系。在Type3中是否有可能只是验证作者关系是否存在,而不是递归地验证它(作者)的所有属性和关系Validation 模型中关系属性的类型3验证,validation,extbase,typo3-9.x,Validation,Extbase,Typo3 9.x,我的extbase扩展中有一个模型,如下所示。 默认情况下,Type3将递归验证所有作者的属性及其关系。在Type3中是否有可能只是验证作者关系是否存在,而不是递归地验证它(作者)的所有属性和关系 class MyModel { /** * @var string * @validate NotEmpty */ protected $title = ''; /** * @var \MyAnotherModel * @co
class MyModel
{
/**
* @var string
* @validate NotEmpty
*/
protected $title = '';
/**
* @var \MyAnotherModel
* @copy reference
*/
protected $author;
Extbase支持两种类型的验证(请参阅)
- 模型验证
- 控制器动作验证
- 忽略
(Author
在初始源代码中)上的属性验证MyAnotherModel
- 只需断言
属性的基数(author
在初始源代码中)MyModel.author
@验证控制器动作中的
工具书类
- 文件:
- 上下文中的源代码示例:
- 自定义验证程序:
控制器中的注释:@Validate
class MyModelCardinalityValidator extends AbstractValidator
{
public function isValid($value)
{
if (!$value instanceof MyModel) {
throw new \LogicException('...');
}
if ($value->getAuthor() === null) {
$this->addError('Author is missing', 1577381508);
// 1577381508 = unix-timestamp as "unique error code"
}
}
}
class MyController extends ActionController
{
/**
* @param MyModel $model
* @TYPO3\CMS\Extbase\Annotation\Validate("NamespaceTo\MyModelCardinalityValidator", param="model")
*/
public function myAction(MyModel $model)
{
// your application code
}
}