我创建了一个实体Testme并使用它生成了 crud 文件bin/console make:crud并尝试向表单添加验证规则,但它不起作用:
我的实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\TestmeRepository")
*/
class Testme
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Assert\NotBlank()
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
....
Run Code Online (Sandbox Code Playgroud)
表格:
<?php
namespace App\Form;
use App\Entity\Testme;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TestmeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder …Run Code Online (Sandbox Code Playgroud)