我知道这篇文章在这里很受欢迎,关于这个问题有很多问题,但没有任何帮助我解决我的问题。我不得不问这个。
我创建了一个名为“ATL15/GoogleAnalyticsBundle”的包。
我想从 app/config.yml 获取用户参数;这是我的配置参数,我正在从 app/parameters.yml 加载参数。
atl15_google_analytics:
client_id: "%ga_client_id%"
client_secret: "%ga_client_secret%"
developer_key: "%ga_developer_key%"
redirect_uri: "%ga_redirect_uri%"
我做了所有我从 symfony 文档书和网络上读到的东西。对我一点帮助都没有……
这是我的DependencyInjection/Configuration.php
文件:
<?php
namespace ATL15\GoogleAnalyticsBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder,
Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('atl15_google_analytics');
$rootNode->children()
->scalarNode('client_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('client_secret')->isRequired()->cannotBeEmpty()->end()
->scalarNode('developer_key')->isRequired()->cannotBeEmpty()->end()
->scalarNode('redirect_uri')->isRequired()->cannotBeEmpty()->end()
->end();
//var_dump($rootNode); die;
return $treeBuilder;
}
}
这是我的DependencyInjection/ATL15GoogleAnalyticsBundleExtension.php
文件:
<?php
namespace ATL15\GoogleAnalyticsBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension,
Symfony\Component\DependencyInjection\Loader;
class ATL15GoogleAnalyticsExtension extends Extension
{
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'));
foreach (array('config') as $basename) {
$loader->load(sprintf('%s.yml', $basename));
}
foreach (array('client_id', 'client_secret', 'developer_key', 'redirect_uri') as $attribute) {
$container->setParameter($attribute, $config[$attribute]);
}
}
public function getAlias()
{
return 'atl15_google_analytics';
}
}
app/AppKernel.php
是的,我从;加载了这个包。
new ATL15\GoogleAnalyticsBundle\ATL15GoogleAnalyticsBundle(),
每次我收到此错误时:
[2013 年 9 月 14 日星期六 17:37:24] [错误] [客户端 127.0.0.1] PHP 致命错误:未捕获的异常 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' 带有消息'没有扩展能够加载配置“atl15_google_analytics”(在 /var/www/vsy-bio/src/ATL15/GoogleAnalyticsBundle/DependencyInjection/../Resources/config/config.yml 中)。寻找命名空间“atl15_google_analytics”,在 /var/www/vsy-bio/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:290\n堆栈跟踪:\n#0 / var/www/vsy-bio/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php(260): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->validate(Array, '/var/ www/vsy-bi...'
请你帮助我好吗?