T
T
TANK_IST2017-08-05 21:30:42
symfony
TANK_IST, 2017-08-05 21:30:42

Why is the symfony validator not working?

There is an essence

<?php
namespace Model;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="Repository\UserModel")
 * @ORM\Table(name="`user`")
 * @ORM\HasLifecycleCallbacks()
 */
class UserModel extends \Core\ModelCore
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="user_id")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @Assert\Email()
     */
    protected $email;

    /**
     * @ORM\Column(type="string", length=100)
     * @Assert\Length(
     *     min = 2,
     *     max = 100
     * )
     * @Assert\NotBlank()
     */
    protected $fname;

    //.....

Controller
$user    = new UserModel;

    //Заполняю данные

    $validator = Validation::createValidator();
    $errors = $validator->validate($user);

But errors do not appear, I do not fill in fname on purpose, but the $errors variable is like this
ConstraintViolationList {#103
  -violations: []
}

I only use symfony components, not symfony itself.
Why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2017-08-05
@TANK_IST

https://symfony.com/doc/current/components/validat...
The configuration in annotations must be included explicitly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question