How do I make Symfony2 autoload my routing.yml for my bundles that I create in vendors folder?

南笙酒味 提交于 2019-12-25 05:27:22

问题


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

Within the vendors folder the folder structure of the bundle is

VendorName\VendorName\Bundles\SampleBundle

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.

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:

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.

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

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?


回答1:


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:   /



回答2:


You should make a route loader as described in the documentation

Also as pointed by Pazi, configure your bundle's composer.json

and finally add in your root composer.json:

"repositories": [
{
    "type":"git",
    "url":"/home/dev/bundle.git"
}
],
"require":{
    "my/bundle":"dev-master"
}


来源:https://stackoverflow.com/questions/17346821/how-do-i-make-symfony2-autoload-my-routing-yml-for-my-bundles-that-i-create-in-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!