如何让 Symfony2 为我在 vendor 文件夹中创建的包自动加载我的 routing.yml? [英] How do I make Symfony2 autoload my routing.yml for my bundles that I create in vendors folder?

查看:17
本文介绍了如何让 Symfony2 为我在 vendor 文件夹中创建的包自动加载我的 routing.yml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用控制台创建了一个示例包.玩了一段时间.现在,我将它移到了 vendor 文件夹中.

I have created a sample bundle using console. Played with it for a while. Now, I moved it to vendors folder.

在 vendor 文件夹中,bundle 的文件夹结构是

Within the vendors folder the folder structure of the bundle is

VendorName\VendorName\Bundles\SampleBundle

我已将命名空间添加到 composer/autoload_namespaces.php 中,并在 AppKernel.php 中成功注册了该包.在SampleBundle/Resources/config文件夹中,有一个routing.yml,里面有之前定义的路由信息​​.

I had added the namespace into composer/autoload_namespaces.php and in AppKernel.php I successfully registered the bundle. In the SampleBundle/Resources/config folder, there is a routing.yml which has the previously defined routing information.

当包在 src 文件夹中时,路由工作正常.我在 app/config/routing.yml 下面定义了

When the bundle was inside src folder the routing was working fine. I had in app/config/routing.yml the below definition

biberltd_currency:
    resource: "@VendorNameSampleBundle/Resources/config/routing.yml"
    prefix:   /

根据上面的定义,我得到以下错误:

With the above definition I get the following error:

无法从D:/localdev/www/symfony/app/config\routing.yml"导入资源@VendorNameSampleBundle/Resources/config/routing.yml.请确保@VendorNameSampleBundle/Resources/config/routing.yml".yml"包已正确注册并加载到应用程序内核类中.

Cannot import resource "@VendorNameSampleBundle/Resources/config/routing.yml from "D:/localdev/www/symfony/app/config\routing.yml". Make sure the "@VendorNameSampleBundle/Resources/config/routing.yml" bundle is correctly registered and loaded in the application kernel class.

当我从 app/config/routing.yml 中删除路由定义时,错误消失但路由不起作用.

When I remove the routing definition from app/config/routing.yml, the error disappears but the route doesn't work.

看到这个,我检查了很多示例包,但我找不到它们如何处理位于 vendor 文件夹中的包的包控制器的路由.

Seeing this I checked a lot of the sample bundles but I couldn't find how they handled the routing of bundle controllers for bundles that reside in vendors folder.

谁能帮我解决这个问题?

Can anyone help me out with this?

推荐答案

我好像遇到了命名空间问题.现在,在更正resource:"中的命名空间后,包括app/config/routing.yml 中的资源.

It seems like I had a namespace issue. Now, after correcting the namespace in "resource:" including resource in app/config/routing.yml works.

biberltd_currency:
    resource: "@VendorNameSampleBundle/Resources/config/routing.yml"
    prefix:   /

这篇关于如何让 Symfony2 为我在 vendor 文件夹中创建的包自动加载我的 routing.yml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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