在Symfony 2.1中没有工作注释验证

时间:2012-11-06 08:06:22

标签: symfony validation symfony-2.1

实体属性:

 /**
 * @var string $content
 *
 * @ORM\Column(name="content", type="string", length=300)
 * @Assert\NotBlank(message="Please enter question")
 * @Assert\Length(
 *   min = "15",
 *   max = "300",
 *   minMessage = "Text question must be larger than 15 symbol",
 *   maxMessage = "Text question must be less than 300 symbol"
 * )
 */
protected $content;

表单提交(在控制器中):

// Add questions
if ($request->getMethod() === 'POST') {
  $formQuestion->bind($request);

  if ($formQuestion->isValid()) {
    // Here code save question
  }
  else {
    $errors = $formQuestion->getErrors():
    // Null array ((
  }
}

没有错误显示(( 为什么不读取注释验证。其他属性是很好的验证。

1 个答案:

答案 0 :(得分:1)

 is you set form reset tag in your twig template 

like this 
 {{ form_rest(form) }}