In the first versions of Sf2 (first Beta's), there was an option, to declare your route separators, like
options: { segment_separators: ['/'] }
But now, it is out of use, and i'm searching the way, to make pretty routes, like:
category:
pattern: /category+{cat}+page{page}
defaults: { _controller: MyPrettyBundle:Category:index }
And now i get this error:
No route found for "GET /category firstcategory page1"
404 Not Found - NotFoundHttpException
1 linked Exception: ResourceNotFoundException
As you can see, '+' is just cutted out of required route.
Any ideas how can i overcome this nasty error?
Fix issues with url decoding!
For URL encoding the + character is used to encode spaces. The URL is decoded before it's parsed, so to use actual + characters in the URL you would have to encode them as %2B:
/category%2Bfirstcategory%2Bpage1
That's not pretty, so using + as separator is not a good idea.
Related
I am just learning symphony please bear with me. I do not want to blindly copy and paste stuff without a real meaning.
In routes.yaml i am seing string such as this :
route1:
path: /foo
defaults: { _controller: 'MyController::fooAction' }
why does "_controller" use the underscore? how would i know that it need the underscore without saying : "that is just the way to use it" ?
why are they using :: to refer to a function method that is not a static method?
How do i get a list of all the keys/value syntax for that that router file?
where do i get the hierarchy of the key/value pair of the yaml file?
In other places i am seeing string like this:
app_lucky_number:
path: /lucky/number
controller: App\Controller\LuckyController::number
This one looks cleaner but where is the underscore in word "controller"?
Why so many inconsistencies?
BTW: I have read this: BTW: I read this: http://symfony.com/doc/current/components/routing.html#defining-routes
it is stated that a full route has seven parts but how do i know the proper syntax of those parts?
Any insights will be appreciated...
Thanks.
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: .+
I have following route:
library_filter_by_genre:
path: /library/genre/{genre}/
defaults: { _controller: noxaeternaMainBundle:Library:filterByGenre }
requirements:
genre: "^[-_\w\d]+$"
It of course works excellent, but I need UTF-8 support. So I've thought that adding of modifer will allow me to use UTF-8, but with the u modifer route doesn't work even with English letters and numbers. I see error:
No route found for "GET /library/genre/123abc/"
Thanks for reading, I hope you can help.
I have problem with urls in my Symfony 2.3 aplication.
I have defined routing like this:
home_how_to_buy:
path: /strefa-wiedzy#jak-kupic
defaults:
_controller: FrameworkBundle:Template:template
template: 'GLHomeBundle:Default:faq.html.twig'
The problem is that when I create links for this page I have something like:
app_dev.php/strefa-wiedzy%23jak-kupic
I have been looking for escaping in yml files, but none of those solutions work for my path.
I will be gratefull for any help.
As stated in my answer here the hashtag is not intended to be in symfony routing. You can do the suggested workaround. But first you should consider, do you really need url-fragments in routing?
PHP's rawurlencode() encodes all chars except a-zA-Z0-9-._~ according to RFC 3986. But we want to allow some chars to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g. ? and # (would be interpreted wrongly as query and fragment identifier), ' and " (are used as delimiters in HTML).
Ich have a problem with symfony2(2.0.16) routing.
I try to run 2 routes like
route1:
host/my/route/{param}
requirements:
param: ".*[^/]$"
route2:
host/my/route/category/{param}
requirements:
param: ".*[^/]$"
As you can imagine, the second route will not be called, not matter what..
what i actually want to do is a search and a specialized search, therefore i need to allow also dots, plus and slashes..
I tried to encode the slash (urlencode to %2F or %252F) so that i can change the requirement, but symfony always decodes it before the routing, so i get an routing error if i remove the requirement.
I thought about to use base64 encoding, but that cant be the solution to my problem..
EDIT: i can also not rely on the order of the routes, because i import the routes from many diffrent bundles..
#This one before the other to be considered !
route2:
host/my/route/category/{param}
requirements:
param: ".+"
route1:
host/my/route/{param}
requirements:
param: ".+"
The parameter for your first route can't be category else it will match it instead of ignoring it. You can change the regex to ignore this value:
route1:
host/my/route/{param}
requirements:
param: "(?!category/).*[^/]$"
route2:
host/my/route/category/{param}
requirements:
param: ".*[^/]$"
Now a parameter called category followed by a slash will be ignored and the pattern won't match, except by the second route.