2016-04-07 7 views
0

新生児のSymfonyフレームワークはここにあります。私はトラフHow to Create a custom Route Loaderクックブックのセクションに行くと、私のバンドルで動作しているが、成功せずにルーティングオートロードをしようとしている。ここでは、すべてこのトピックファイルに関連していますsymfony 3 - バンドルからのルートをLoaderクラスによって動的に追加します

ローダー:

namespace Notimeo\CoreBundle\Routing; 

use Symfony\Component\Config\Loader\Loader; 
use Symfony\Component\Routing\RouteCollection; 

class AdvancedLoader extends Loader 
{ 
    public function load($resource, $type = null) 
    { 
     $collection = new RouteCollection(); 

     $resource = '@NotimeoCoreBundle/Resources/config/import_routing.yml'; 
     $type  = 'yaml'; 

     $importedRoutes = $this->import($resource, $type); 

     $collection->addCollection($importedRoutes); 

     return $collection; 
    } 

    public function supports($resource, $type = null) 
    { 
     return 'advanced_extra' === $type; 
    } 
} 

依存性の注入:

namespace Notimeo\CoreBundle\DependencyInjection; 

use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; 
use Symfony\Component\HttpKernel\DependencyInjection\Extension; 
use Symfony\Component\DependencyInjection\ContainerBuilder; 
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; 
use Symfony\Component\Config\FileLocator; 

class CoreExtension extends Extension implements PrependExtensionInterface 
{ 
    public function load(array $configs, ContainerBuilder $container) 
    { 
    } 

    public function prepend(ContainerBuilder $container) 
    { 
     $loader = new YamlFileLoader(
      $container, 
      new FileLocator(__DIR__.'/../Resources/config') 
     ); 
     $loader->load('services.yml'); 
    } 
} 

のsrc/Notimeo/CoreBundle /リソース/設定/ routing.ymlファイル:

notimeo_core_routes: 
    resource: . 
    type: advanced_extra 

のsrc/Notimeo/CoreBundle /リソース/設定/ import_routing.yml:

# homepage 
homepage: 
    path:/
    defaults: 
     _controller: CoreBundle:Base:index 

のsrc/Notimeo/CoreBundle /リソース/設定/ services.yml:

services: 
    routing.loader.advanced_loader: 
     class: Notimeo\CoreBundle\Routing\AdvancedLoader 
     tags: 
      - { name: routing.loader } 

取得No route found for "GET /"エラー...

(symfony 3を使用)


UPDATE:私はのsrc/Notimeo/CoreBundle /リソース/設定/ routing.ymlファイルの内容を移動する場合

うーん...それは働いている:

にアプリ/設定を/routing.yml

しかし...なぜですか?なぜ私のバンドルにすべてのコンテンツを入れることができないのですか?

答えて

2

あなただけ

my_custom_route: 
    resource: "@NotimeoCoreBundle/Resources/config/routing.yml" 
_ app/config/routing.yml

に以下の行を追加するだけでapp/config/routing.yml

に含めるようにしてくださいsrc/Notimeo/CoreBundle/Resources/config/routing.yml内のすべてのコンテンツを置くことができます

関連する問題