实体属性:
/**
* @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 ((
}
}
没有错误显示((为什么不读取注释验证。其他属性很好验证。