使用驗證組...
實體類:
// src/Acme/BlogBundle/Entity/User.php
namespace Acme\BlogBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
class User implements UserInterface
{
/**
* @Assert\Email(groups={"registration"})
*/
private $email;
/**
* @Assert\NotBlank(groups={"registration"})
* @Assert\Length(min=7, groups={"registration"})
*/
private $password;
/**
* @Assert\Length(min = "2")
*/
private $city;
}
然後,當你創建你的表格:
$form = $this->createFormBuilder($users, array(
'validation_groups' => array('registration'),
))->add(...);
這則只驗證email
和password
字段。在確認團組
文檔是here和here
這工作,雖然我用了不同的方法。我手動添加了驗證器(如Zend_Form),並獲得了一個數組而不是實體,並使用它來檢查憑據。 – 2013-05-09 01:47:33