symfony-cmf / routing-bundle

Symfony bundle to provide the CMF chain router to handle multiple routers, and the dynamic router to load routes from a database or other sources.
161 stars 78 forks source link

Lesson for routing - Questions #262

Closed ElectricMaxxx closed 9 years ago

ElectricMaxxx commented 10 years ago

Hey,

would need some clearing work in my head for the routing and the values i can set when using the admin (with sonata admin) for the routes. I have got an example to show my problem.

On the one hand i have got routes of some documents that i created while creation of the documents. Those got a little prefix for the domain they belong to, like a bicycle tour route is persisted in:

/cms/routes/www.my-domain.de/tours/example-tour

I have got a route provide and a filter to get the matches depending on the current host/domain. That works fine and is cool. But now i wanna have routes with parameters and match a controller:action and wanna provide one of that parameter routes in the menu. So i thought i need to create a route like:

/cms/routes/www.my-domain.de/service/{service-name}

means a route with a localname service and an parameter severice-name But when navigating to that route i got an 404. The thing i wanna have is:

bobb_projectx_tour.themes:
    defaults: { _controller: bobb_projectx_tour.controller.tour_content:themesAction, tourName: neckartal-radweg }
    path: /informationen/themenbereiche/{tourName}

here i create a simple symfony route with the same behavior, cause i did not get it with the cmf routing. Is it possible that i destroy some stuff of the route matching, caused by my own route provider? Is there an easier way then with the route provider? Haven't found a doc about that candidate stuff.

And what would be the part (when it work) to put into the menu route field? I thought the route name is that part, which the route is able convert into a route object with an matching content document, right? So i would need to insert /www.my-domain.de/servcice/e-bike-station (special service) into my route field of the menu entry?

dbu commented 10 years ago

in phpcr-odm, you should be able to put your route at /cms/routes/www.my-domain.de/service and define a parameter service-name. this would lead to the pattern you describe. try to debug the list of paths the candidates strategy delivers for /cms/routes/www.my-domain.de/service/my-thing - it should contain the /cms/routes/www.my-domain.de/service path. note that unless you define a requirement like .*, a parameter can not contain /.

about the defaults: having a default can make sense - although in a REST way of thinking, /service should be the list of services rather than one specific service. i would not recommend to configure the controller this way. rather use the route type and configure controller-by-type.

ElectricMaxxx commented 10 years ago

defining the controller that way was just my escape cause i did not get the the cmf way or the routes working. It is my destination to let it work with the cmf routes, cause i wanna have the possibility t o manage the routes in the backend. But ok, i will debug through my candidates where my parameters are missing.

ElectricMaxxx commented 10 years ago

btw: controller-by-type is nice, but i can't add a new type in my admin atm. got an empty list and no chance to add.

dbu commented 10 years ago

controller-by-type: you first need to configure the available types so that you can chose from them.

ElectricMaxxx commented 10 years ago

you see there is some more clearing work needed in my head :-)

I can't do the scenario described above with candidates? How? Cause the default route provider is aware of parameters and solves the matches with nice reg. expresion.

dbu commented 10 years ago

the stored routes in phpcr-odm just have the "static prefix" which is what the candidates match. then the candidate routes are "compiled" into the regexp thing, where they add their parameters.

as the doc about dynamic routing says, the candidates should take a very simplistic and cheap approach to provide potentially matching routes. the actual matching is left to the symfony route matcher which does that very well.

dbu commented 9 years ago

@ElectricMaxxx can we close this one or do we need to still do something about this?

ElectricMaxxx commented 9 years ago

Close.