5

I'm creating an application with Symfony 2.3.5 to manage my music. I have some problems to configure my routes.

I want to create 3 routes :

  • Show Artist : /music/mickael_jackson
  • Edit Artist : /music/mickael_jackson/edit
  • Show Album : /music/mickael_jackson/thriller

As you can show, there will be a conflict between routes for 'Edit Artist' and for 'Show album' : 'Edit Artist' is catched as the 'Show album route' and give me a 404 not found.

I'm trying to use regular expressions to exclude keywords edit and delete from route 'Show album'.

I have found one here : A regular expression to exclude a word/string (Accepted answer with a little change), but it doesn't work, I have an error because my route 'Show album' did not match regex.

Exception :

An exception has been thrown during the rendering of a template ("Parameter "nameCanonical" for route "corum_music_album_show" must match "/(?!edit|delete)" ("beneath_the_encasing_of_ashes" given) to generate a corresponding URL.") in CorumMusicBundle:Artist:show.html.twig at line 36. 

My route :

* @Route(
*         "{artistNameCanonical}/{nameCanonical}",
*         name = "corum_music_album_show",
*         requirements={"nameCanonical" = "^/(?!edit|delete)$"},
*         options = {"expose"=true}
* )

I can't find what's wrong in the configuration.

Thanks for help.

Community
  • 1
  • 1
Elorfin
  • 2,487
  • 1
  • 27
  • 50

3 Answers3

4

use this pattern ^(?!.*(edit|delete)$).* I don't know Symfony either

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
alpha bravo
  • 7,838
  • 1
  • 19
  • 23
0

Remove the forward slash,

*         requirements={"nameCanonical" = "^(?!edit|delete)$"},

since it's already included in your total path.

Otherwise, the regex looks okay to me; nice work, finding the answer on your own. Most people new to regular expressions have trouble with applying lookaround assertions.

Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
  • Thank's for help but I still have the same exception. Regular expressions are the most complicated things I learn and it is still a mystery to me... – Elorfin Oct 09 '13 at 17:06
  • Hm, Sorry, I don't know enough about Symfony to help you, then. I've upvoted your question though; hopefully someone else can help you. – Andrew Cheong Oct 09 '13 at 17:14
0

Just move your "Edit artist" route before "Show Album" route. Of course, you won't be able to use "edit" as a name of an album, but I suppose you can live with that.

Massimiliano Arione
  • 2,422
  • 19
  • 40