2012-02-03 4 views
33

어디에도 저장할 오브젝트가없는 상태에서 폼의 유효성을 검사해야하는 경우가 있습니다. 이 시나리오에서 나는 여전히 교리가없는 엔터티를 만들고 폼이 유효하거나 다른 방법이 있다면 원하는 것을 수행하기 위해 ususal로 유효성을 검사합니까?Doctrine Entity가없는 폼 유효성 검사

예를 들어 그의 이름으로 이메일을 사용자에게 보냅니다.

답변

61

Using a Form without a Class 섹션을 참조하십시오. 유효성 검사에 대한 하위 절도 있습니다.

답은 직접 제약 조건을 설정하고 개별 필드에 연결하는 것입니다.

use Symfony\Component\Validator\Constraints\Length; 
use Symfony\Component\Validator\Constraints\NotBlank; 

$builder 
    ->add('firstName', 'text', array(
     'constraints' => new Length(array('min' => 3)), 
    )) 
    ->add('lastName', 'text', array(
     'constraints' => array(
      new NotBlank(), 
      new Length(array('min' => 3)), 
     ), 
    )) 
; 
+3

는 이제이 페이지의 : https://symfony.com/doc/current/form/without_class.html –