简体   繁体   中英

How to allow a “?” character in a route parameter in Symfony2?

I would like to know how to allow a "?" character in a route parameter in Symfony2. This is the route that I have (actually, the route parameter I am focusing on is "messtext"):

ikproj_groupe_sendreply1:
pattern:  /{groupid}/{receiver}/{messtext}/{cible}/sendreply
defaults: { _controller: IkprojGroupeBundle:Messages:SendReply1 }
requirements:
    messtext: .+

In fact, I had a look at this link: http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html which is about how to allow a "/" character in a route parameter in Symfony2. I did what I learnt from that tutorial exactly but the problem is that it doesn't work: Symfony2 still displays this error message: No route found for "GET /groupe/sendreply/11/28/hello,%20dear%20sir...can%20I%20join%20your%20group"

So, my questions are: what is wrong in my code above and how can I resolve that?

Only 1 parameter of your route may accept '/' character. And this MUST be the last one as every following one are considered as part of the param value... In your case, Symfony routing never detect cible and sendreply parts of the URL.

Try to put messtext param at the very end of the URL :

ikproj_groupe_sendreply1:
pattern:  /{groupid}/{receiver}/{cible}/sendreply/{messtext}
defaults: { _controller: IkprojGroupeBundle:Messages:SendReply1 }
requirements:
    messtext: .+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM