0

我有一个MyProject\SecurityBundle\Entity\User带有验证约束的用户模型。对于我的注册,我创建了MyProject\SecurityBundle\Form\Model\Registration

namespace MyProject\SecurityBundle\Form\Model;

use MyProject\SecurityBundle\Entity\User;

class Registration
{
    private $user;

    private $termsAccepted;

    public function setUser(User $user)
    {
        $this->user = $user;
        return $this;
    }

    public function getUser()
    {
        return $this->user;
    }

    public function setTermsAccepted($termsAccepted)
    {
        $this->termsAccepted = (boolean)$termsAccepted;
        return $this;
    }

    public function getTermsAccepted()
    {
        return $this->termsAccepted;
    }
}

经验证:

MyProject\SecurityBundle\Form\Model\Registration:
    properties:
        user:
            - Type: { type: MyProject\SecurityBundle\Entity\User }
        termsAccepted:
            - NotBlank: ~
    getters:
        termsAccepted:
            - "True": ~

此验证有效,但用户实体的验证被此绕过。有没有办法可以将验证传输到我的注册模型中?

4

1 回答 1

0

如果我在正确的地方进行了搜索,我会在文档中找到http://symfony.com/doc/2.0/reference/constraints/Valid.html并提供解决方案:

MyProject\SecurityBundle\Form\Model\Registration:
    properties:
        user:
            - Type: { type: MyProject\SecurityBundle\Entity\User }
            - Valid: ~
于 2012-12-24T13:17:56.627 回答