2

I want to validate my form. I created validation.yml file in the config folder, my bundle is registered and the file is loaded in DependencyInjection. I get the following error:

There is no extension able to load the configuration for "Developer\Forum\ForumBundle\Entity\Registration" (in /var/www/html/forum/src/Developer/Forum/ForumBundle/DependencyInjection/../Resources/config/validation.yml). Looked for namespace "Developer\Forum\ForumBundle\Entity\Registration", found none

My validation.yml:

Developer\Forum\ForumBundle\Entity\Registration:
    properties:
        name:
            - NotBlank: ~
        surname:
            - NotBlank: ~

DependencyInjection:

namespace Developer\Forum\ForumBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Developer\Forum\ForumBundle\Entity\Registration;

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class DeveloperForumForumExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('validation.yml');
    }
}

The form itself is working fine, data is saved into the database, but I need some validation. What is missing?

3
  • Try simply to don't load this files in the bundle extension class. So remove the line $loader->load('validation.yml'); Commented Feb 8, 2015 at 14:55
  • Without this, validate doesn't work :( Commented Feb 8, 2015 at 15:01
  • check the config.ymlfiles the section about framework: ... validation: { enabled: true } Commented Feb 8, 2015 at 15:09

1 Answer 1

2

/app/Resources/config/validation.yml is loaded automatically. Don't load it for your configuration, this is wrong.

Add this to your configuration instead, to enable validation and don't let PHP parse annotations.

framework:
    validation:
        enabled: true
        enable_annotations: false

If you want to add userdefined ymls for validation, you can append it to the parameter validator.mapping.loader.yaml_files_loader.mapping_files, (Symfony2 how to load validation.yml)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.