You are not snarky. I know snarks well, and I’m currently hunting one. The doc is not as helpful as it should be. I learn by mistakes, and I know others will benefit from them. Ad augusta per angusta.
However, in these pages https://gist.github.com/K-Phoen/6974497 and http://symfony.com/doc/current/components/dependency_injection.html, the authors used :
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
and then :
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Hence my confusion on the /YamlFileLoader + Loader\ parts.
The service part works fine now. But… another error message popped up :
ParameterNotFoundException in ParameterBag.php line 84: You have requested a non-existent parameter “validator.mapping.loader.yaml_files_loader.mapping_files”.
I rechecked the paths, added a line to build the container. The file is now
<?php
// src/AppBundle/DependencyInjection/AppExtension.php
namespace AppBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\FileLocator;
/* */
class AppExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$container = new ContainerBuilder();
// Services
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../../../app/config'));
$loader->load('services.yml');
// Validation
$yamlMappingFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$yamlMappingFiles[] = __DIR__.'/../../../app/Resources/config/validation.yml';
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $yamlMappingFiles);
}
}
I checked in $container, and no forementioned parameter (why ? Should there be one ? If so, why is it missing ? No useful google occurence of this parameter…), so I commented the getParameter line, and no more error message.
But still no validation. I got back to :
An exception occurred while executing ‘INSERT INTO tasks (task_name, task_due_date) VALUES (?, ?)’ with params [null, “2011-01-01 00:00:00”]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘task_name’ cannot be null
So, no validation, the form is valid in any case… Puzzling.
In my form controller, I checked for errors with the validator (http://symfony.com/doc/current/validation.html)
[...]
if($form->isSubmitted())
{
if($form->isValid())
{
$validator = $this->get('validator');
$errors = $validator->validate($taskSet);
echo'<pre>';
var_dump($errors);
echo'</pre>';
die();
[...]
No error shows up, so the validation.yml file is either not loaded, or ignored.