Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same bundle different routes

I need to have different routes pointing to the same bundle. Ex: /mkt/contacts and /crm/contacts should pointing to the same contact bundle.

Why? I am developing a platform (one symfony2 project), that have many applications (A marketing application, a CRM application and more. Each application is a group of modules (bundles), some of them are shared between applications (Like ContactsBundle).

What I need to do is that the route prefix of the shared bundles are relative to the current application, so if the user is in the Marketing Application (/mkt/) then the route prefix to the ContactBundle should be /mkt/contact. But if it is in the CRM application it should be /crm/contacts

I think I can create two route resources in routing.yml like so:

route1:
    resource: "@Contactundle/Resources/config/routing.yml"
    prefix:   /crm/contact
route2:
    resource: "@ContactBundle/Resources/config/routing.yml"
    prefix:   /mkt/contact

The biggest problem is in the views when using path function. How do I know the name of the route? The only possible solution I can think of is to create some twig extension which checks the current pathinfo and return the correct route prefix.

Any better ideas?

like image 492
brpaz Avatar asked Nov 11 '22 13:11

brpaz


1 Answers

you should use one route but use mkt and crm as a variable.

contact:
    path:      /{ prefix }/contact
    defaults:  { _controller: YourContactBundle:Contact:contact }

Then in twig or wherever you want

{{ path('contact', { 'prefix': prefix } ) }}

You should retrieve the variable contact by session or by giving parameters to the route.

As it's just some few bundles who are in common, i would recommend to give the parameter. In home of the market app, i would call the contact form by {{ path('contact',{ 'app_prefix' : constant_prefix_mkt} ) }}

like image 138
goto Avatar answered Dec 09 '22 22:12

goto