2016-09-28 58 views
2

引言
我知道。在這個確切的話題上有成千上萬的帖子,但不知何故,我仍然無法解決這個問題。我總是得到錯誤有沒有擴展能夠加載配置...尋找命名空間「...」,發現沒有

There is no extension able to load the configuration for "first" (in /var/www/app/src/tzfrs/SpotifyBundle/DependencyInjection/../Resources/config/settings.yml). Looked for namespace "first", found none

目的
我創建了一個包,並希望有自定義配置選項,但因爲它們比通常的文件比較大,我不希望把它在config.yml,但在我自己的文件。

說明
我對包項目結構看起來像這樣/src/tzfrs/SpotifyBundle

捆裏面我已經創建的文件

  • ./TzfrsSpotifyBundle.php
  • ./DependencyInjection/Configuration.php
  • ./Resources/config/settings.yml

我有,當然,註冊了捆綁在AppKernel,一切工作正常,到目前爲止同捆,除了新的配置我想補充的TzfrsSpotifyBundle

內容

<?php 
namespace tzfrs\SpotifyBundle; 

use tzfrs\SpotifyBundle\DependencyInjection\TzfrsSpotifyExtension; 
use Symfony\Component\HttpKernel\Bundle\Bundle; 

class TzfrsSpotifyBundle extends Bundle 
{ 
} 

/DependencyInjection/Configuration.php內容(最小化到只有相關的信息)

public function getConfigTreeBuilder() 
{ 
    $treeBuilder = new TreeBuilder(); 
    $rootNode = $treeBuilder->root('first'); 

    $rootNode 
     ->children() 
      ->booleanNode('secondary')->defaultTrue()->end() 
     ->end(); 

    return $treeBuilder; 
} 

的內容(最小化,以唯一相關的信息)的./Resources/config/settings.yml

first: 
    secondary: false 

理念

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('settings.yml'); 
} 

內容,如果有更多的問題上來,或將無法正常工作的建議,我將隨信息更新本節


+0

我假設你已經檢查了手冊? http://symfony.com/doc/current/bundles/configuration.html你的根節點將會像tzfrs_spotify一樣。這就是Symfony如何知道特定包的配置值。也許看看框架包配置文件。 – Cerad

+0

是的,我檢查了,但也沒有工作。 – Musterknabe

回答

0

請確保您拼寫正確,並確保您的擴展類實際上被調用。如果您沒有正確命名擴展名,那麼它將不會被加載。我只是測試了這個,它工作正常:

cerad_spotify: 
    first: 
     secondary: false 

class CeradSpotifyBundle extends Bundle 
{ 
} 

namespace Cerad\SpotifyBundle\DependencyInjection; 

class Configuration implements ConfigurationInterface 
{ 
    public function getConfigTreeBuilder() 
    { 
     $treeBuilder = new TreeBuilder(); 
     $rootNode = $treeBuilder->root('cerad_spotify'); 
     $rootNode 
      ->children() 
       ->arrayNode('first') 
        ->children() 
         ->booleanNode('secondary')->end() 
        ->end() 
       ->end() // first 
      ->end() 
     ; 
     return $treeBuilder; 
    } 
} 

namespace Cerad\SpotifyBundle\DependencyInjection; 

class CeradSpotifyExtension extends Extension 
{ 
    public function load(array $configs, ContainerBuilder $container) 
    { 
     $configuration = new Configuration(); 

     $config = $this->processConfiguration($configuration, $configs); 

     VarDumper::dump($config); 
    } 
}