如果已加载bundle,则加载路由



我有一个API捆绑包,只有当我在子域上时才能加载,以下是我的AppKernel中的内容:

if ($_SERVER['HTTP_HOST'] == 'api.mywebsite.fr')
{
    $bundles[] = new TVApiBundleTVApiBundle();
}

现在,我需要在捆绑包中的某个位置加载它自己的路由,而不必使用捆绑包配置修改app/config/routing.yml文件。我尝试使用自定义路由器加载程序,如下所述http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html但问题是教程的一部分:

AcmeDemoBundle_Extra:
    resource: .
    type: extra

有没有办法避免这种配置我希望我的捆绑包是独立的,并且在不必修改app/config/中的文件的情况下完成所有工作(除了c:p的AppKernel部分)

问候,

您检查了文档的最后一部分吗?这部分在自定义加载程序中添加资源和类型,这样就不必在routing.yml中执行。http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html

namespace AcmeDemoBundleRouting;
use SymfonyComponentConfigLoaderLoader;
use SymfonyComponentRoutingRouteCollection;
class AdvancedLoader extends Loader
{
    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();
        $resource = '@AcmeDemoBundle/Resources/config/import_routing.yml';
        $type = 'yaml';
        $importedRoutes = $this->import($resource, $type);
        $collection->addCollection($importedRoutes);
        return $collection;
    }
    public function supports($resource, $type = null)
    {
        return $type === 'advanced_extra';
    }
}

最新更新