Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route regex requirements : exclude specific words

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.

like image 927
Elorfin Avatar asked Oct 02 '22 17:10

Elorfin


1 Answers

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

like image 160
alpha bravo Avatar answered Oct 10 '22 06:10

alpha bravo