Hi Octavian - On Tue, 27 Oct 2009 23:16 +0200, "Octavian Râsnita" <orasn...@gmail.com> wrote: > From: "Larry Leszczynski" <lar...@emailplus.org> > > Hi Octavian - > > > >> Is there a Catalyst Request method for getting the path and the > >> query_string? (Everything's after the base). > >> > >> I want to use it in a TT template for changing the current language. > >> > >> The current URI is something like: > >> http://www.site.com/prg?var1=val1&var2=val2 > >> > >> The base for this URI is: > >> http://www.site.com/en/ > >> (Because I overwritten prepare_path as in the example given on the Cat > >> wiki) > >> > >> and the URL that should be printed with the new language is: > >> http://www.site.com/ro/prg?var1=val1&var2=val2 > > > > Not sure if this gets you all the way there, but you could call > > "c.req.uri" with no arguments, that should give you the current request > > including base, path and query string. Then you could strip off > > c.req.base from the beginning of that string. > > Thank you Larry, but the problem is that the base was overwritten and it > contains some more than the uri, so I can't cut it from the URI.
It should work fine, we do something very similar. The trick is that after the prepare_path fixup (if you did it like in the wiki), when you stringify c.req.uri, it will reflect the *new* base, not the original. Using your example: original request url: http://www.site.com/prg?var1=val1&var2=val2 rewritten request url: http://www.site.com/en/prg?var1=val1&var2=val2 So you should have: [% uri = c.req.uri; # http://www.site.com/en/prg?var1=val1&var2=val2 base = c.req.base; # http://www.site.com/en/ pattern = '^' _ base; # pattern not tested... path_and_query = uri.replace(pattern, ''); %] So it's easy to strip "base" from the front of "uri" and get what you need, without knowing what "base" is. > Thank you Evan. Your solution was helpful. > I didn't know that c.req.uri is not just a string, but an object that has > its own methods, and c.req.uri.path_query was the one I needed. This could work, but given the same original url and prepare_path fixup, you will have: [% uri = c.req.uri; # http://www.site.com/en/prg?var1=val1&var2=val2 path_and_query = c.req.uri.path_query; # /en/prg?var1=val1&var2=val2 %] So now when you build the new url you have to be aware that path_and_query contains the "/en" part that needs to be stripped. Larry _______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/