自己的 Symfony3 供应商包中的带注释路由 [英] Annotated routing in own Symfony3 vendor bundle

查看:23
本文介绍了自己的 Symfony3 供应商包中的带注释路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个包含多个可重用包的私有生态系统,类似于 Sonata 项目.这是我第一次跟随 Symfony2 - 创建自己的供应商包- 项目和 git 策略,并使用 DefaultController 设置一个名为 PUIEconomyBundle 的简单包.我使用 composer.json 将包从我的 Git 存储库导入到一个示例项目中.

I want to build a private ecosystem with multiple reusable bundles, similar to the Sonata project. This is my first time so I followed Symfony2 - creating own vendor bundle - project and git strategy and set up a simple bundle named PUIEconomyBundle with a DefaultController. I imported the bundle into an example project from my Git repo using composer.json.

现在我遇到了 404 找不到GET/test"的路由.重要的是要有带注释的路线以保持概览.如何将带注释的工作路由引入我的控制器?debug:router 没有提到这个包中的路由,尽管分析器说 PUIEconomyBundle 已启用.

Now i'm running into a 404 No route found for "GET /test". It's important to have annotated routes to keep an overview. How do I introduce working annotated routing into my controllers? The debug:router does not mention the route from this bundle, although the profiler says the PUIEconomyBundle is enabled.

class DefaultController extends Controller
{
    /**
     * @Route("/test", name="homepage")
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction(Request $request)
    {
        dump('Hello!');die;
    }
}

扩展:

public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();
    //$config = $this->processConfiguration($configuration, $configs);

    $fileLocator = new FileLocator(__DIR__.'/../Resources/config');
    $loader = new Loader\YamlFileLoader($container, $fileLocator);
    $loader->load('services.yml');
}

Services.yml:

services:
    pui_economy.routing_loader:
        class: Company\PUI\EconomyBundle\Service\RoutingLoader
        tags:
            - { name: routing.loader }

路由加载器:

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

        $resource = '@PUIEconomyBundle/Resources/config/routing.yml';
        $type = 'yaml';

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

        $collection->addCollection($importedRoutes);

        return $collection;
    }

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

Routing.yml:

pui_economy:
    resource: "@PUIEconomyBundle/Controller"
        type: annotation

谢谢

推荐答案

你好像忘记加这个了:

app_extra:
    resource: .
    type: extra

app/config/routing.yml中.

请参阅使用自定义加载程序.

这篇关于自己的 Symfony3 供应商包中的带注释路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆