Regex for slug in symfont route

1.1k views Asked by At

I'm having trouble creating a Regex to match URL slugs [a-z] ("words" separated by single dashes) like this:

wordone-wordtwo-wordtree

in route:

csa_platform_category:
    path:     /c/{slug}
    defaults: { _controller: CSAPlatformBundle:Category:index }
    requirements:
        slug: "^[a-z]+(?:-[a-z]+)*$"

in twig:

<a href="{{ path('csa_platform_category', {'slug': cat.slug}) }}">{{ cat.name }}</a>

The displayed error is:

An exception has been thrown during the rendering of a template ("Parameter "slug" for route "csa_platform_category" must match "[a-z]+(?:-[a-z]+)*" ("" given) to generate a corresponding URL.").

I'm quite bad with regular expressions, so any help would be appreciated.

1

There are 1 answers

0
goto On

The error you are having is saying than your cat.slug is empty.

("" given)

You should check the data in cat object using var_dump or dump