app/config/config.yml

validation:      { enabled: true, enable_annotations: false }

Bundle/Resources/config/validation.yml

Bundle\Entity\Post:
    properties:
        name:
            - NotBlank: ~
        text:
            - NotBlank: ~

Controller

$entity = new Entity();
$validator = $this->get('validator');
$errors = $validator->validate($entity);
if (count($errors)>0) {
} else {
}

 

1456916553