AppBundle 内でいくつかのパラメーターを定義しようとしていますが、成功しません。これは、このフレームワークでの最初のテストの 1 つなので、誤解している明らかな概念があるかもしれません。
最初の問題は、YAML ファイル内で読み取られないフィールドbundle_versionです。返されるエラーは次のとおりです。
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
The child node "bundle_version" at path "costs" must be configured.
この行にコメントすると、別のエラーが発生します:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
There is no extension able to load the configuration for "costs" (in W:\wamp64\www\test\src\AppBundle\DependencyInjecti
on/../Resources/config\costs.yml). Looked for namespace "costs", found none
src/AppBundle/DependencyInjection/Configuration.php
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('costs');
$rootNode->children()
// THIS LINE DON'T WORK AND CAUSE THE 1st PROBLEM
->floatNode('bundle_version')->isRequired()->end()
->arrayNode('shipping')
->children()
->floatNode('es')->isRequired()->end()
->floatNode('it')->isRequired()->end()
->floatNode('uk')->isRequired()->end()
->end()
->end()
->arrayNode('services')
->children()
->floatNode('serviceA')->isRequired()->end()
->floatNode('serviceB')->isRequired()->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
/src/AppBundle/Resources/config.costs.yml
costs:
bundle_version: 1.0 # THIS FIELD IS NOT RECOGNIZED
shipping:
es: 18.00
it: 19.00
uk: 20.00
services:
serviceA: 15.00
serviceB: 20.00
/src/AppBundle/DependencyInjection/AppExtension.php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class AppExtension extends Extension
{
public function load(array $config, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('costs.yml');
}
}