AppBundle 내부에서 일부 매개 변수를 성공적으로 정의하려고합니다. 이 프레임 워크에 대한 첫 번째 테스트 중 하나이기 때문에 내가 오해 한 분명한 개념이있을 수 있습니다.Symfony 3.1 - AppBundle을위한 전역 매개 변수를 생성하십시오.
첫 번째 문제는 bundle_version입니다.이 문제는 YAML 파일 내에서 읽히지 않습니다. 내가이 줄을 언급 할 때
[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/의존성 주입 /을 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');
}
}