symfony3实体表单验证无效

时间:2016-10-18 15:00:48

标签: forms validation symfony

甚至复制/粘贴这个约束,没什么好处,我也禁用了html验证,这是代码:twig:

{{form_start(form, {'action':'', 'method':'POST'})}}
{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{form_end(form)}}

这里是班级:

class Curso {

/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 * @Assert\MaxLength(15)
 * @ORM\Column(name="titulo", type="string", length=255)
 */
private $titulo;

/**
 * @var string
 * @Assert\NotBlank()
 * @Assert\Length(
 *      min = 2,
 *      max = 50,
 *      minMessage = "Your first name must be at least {{ limit }} characters long",
 *      maxMessage = "Your first name cannot be longer than {{ limit }} characters"
 * )
 * @Assert\Type("string")
 * @ORM\Column(name="descripcion", type="string", length=255)
 */
private $descripcion;

/**
 * @var float
 * @Assert\NotBlank()
 * @ORM\Column(name="precio", type="float")
 */
private $precio;

/**
 * Get id
 * @Assert\NotBlank()
 * @return int
 */
public function getId() {
    return $this->id;
}

/**
 * Set titulo
 *
 * @param string $titulo
 *
 * @return Curso
 */
public function setTitulo($titulo) {
    $this->titulo = $titulo;

    return $this;
}

/**
 * Get titulo
 *
 * @return string
 */
public function getTitulo() {
    return $this->titulo;
}

/**
 * Set descripcion
 *
 * @param string $descripcion
 *
 * @return Curso
 */
public function setDescripcion($descripcion) {
    $this->descripcion = $descripcion;

    return $this;
}

/**
 * Get descripcion
 *
 * @return string
 */
public function getDescripcion() {
    return $this->descripcion;
}

/**
 * Set precio
 *
 * @param float $precio
 *
 * @return Curso
 */
public function setPrecio($precio) {
    $this->precio = $precio;

    return $this;
}

/**
 * Get precio
 *
 * @return float
 */
public function getPrecio() {
    return $this->precio;
}
}
你可以告诉我出了什么问题吗?抱歉我的英语,我有点生疏了:))

1 个答案:

答案 0 :(得分:1)

您可能需要检查app/config.yml并确保您已启用注释进行验证

framework: 
    ...
    validation: { enable_annotations: true }