symfony - Symfony2 character between parameters in route -
so have route
path: /view/{category}-{subcategory}
and i'm trying render route in twig
href="{{ path('my_route', {category: cat.slug, subcategory: sub.slug }) }}"
but symfony throwing me error
an exception has been thrown during rendering of template ("parameter "category" route "my_route" must match "[^/-]++" ("food-cheap" given)
isn't supossed auto generate -
character i'm setting real parameters? if change -
/
works, don't want use slash because it's not uri inside category
.
it work if use this
requirements: category: ".*"
but using slugs (as it's point of this) parameters, goes crazy.
for example category: something
subcategory: super-size
uri /view/something-super-size
symfony2 says that
category = something-super
and
subcategory = size
because has -
, doesn't know stop in regex pattern.
i've found strange behaviour...
if manually type url
http://localhost/view/something-super-size
it goes correctly it's controller, without problems , without using requirements maybe problem @ {{ path() }}
method...
to make route working dash segments separator, declare route :
my_route: path: /view/{category}-{subcategory} defaults: _controller: yourbundle:controller:method requirements: category: "[a-za-z1-9\-_\/]+"
now dash automatically added between params when use
href="{{ path('my_route', {category: cat.slug, subcategory: sub.slug }) }}"
edit
to more precise, given regexp, dash considered uri segment separator, , not part of parameter.
parameters intact (doesn't contain -
) , when generate url path
method, -
automatically added between parameters. regexp make working.
Comments
Post a Comment