简体   繁体   中英

How to create routes in a specific custom bundle in Symfony?

I have created a custom bundle called UserBundle using Symfony console. Now I want to create few user related routes for that bundle. I know that I can write those routes in app/config/routing.yml file, but I want to encapsulate all the routes within their specific bundle.

I know we can do that by creating routing.yml or routing.xml or routing.php file in "src\\UserBundle\\Resources\\config". But I have tried that and it did not worked.

So what I'm missing here? Do we need to autoload those new bundle specific files or clear route cache?

Here is the content from "src\\UserBundle\\Resources\\config\\routing.yml":

login:
    path:      /login
    defaults:  { _controller: UserBundle:User:getLoginForm }

Any help would be appreciated.

Note: I'm totally new to the Symfony.

Thanks

Check this line in app/config/routing.yml :

access:
    resource: "@UserBundle/Resources/config/routing.yml"
    prefix:   /

It should be generated by default, but if it does'n exist just add it. Then you can use routes from UserBundle/Resources/config/routing.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM