Parth Vora
Parth Vora

Reputation: 4114

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

Upvotes: 3

Views: 3696

Answers (1)

blues911
blues911

Reputation: 910

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

Upvotes: 6

Related Questions