Quick regex routing question |
[eluser]darrenm[/eluser]
Hi there I have controller that needs to take loads of arguments from a URL. The amount of arguments will vary. As the URI is going to get pretty long I'm keen to lose the 'function' part of it and re-route along the lines of: Code: /productsearch/(varying*number*of*segments) = /productsearch/listingfunction/(*everything*) Can anyone help me out with the regex specifics? many thanks.
[eluser]darrenm[/eluser]
Ok, I was being lazy. Seems to be as simple as: Code: $route['productsearch/(.)+'] = "productsearch/listing/$1";
[eluser]obiron2[/eluser]
In the past I have had to do this where I had a whole bunch of data that needed to be passed back to the server from a clientside javascript object as the business rules were too complex to carry out without database interaction. I used the javascript serialise functions and the encoded the JSON object with URLEncode and passed the JSON object as a single parameter to the controller where I URLUnecoded it and then unserialised it so that CI would play nicely with it. You should be able to find the Javascript serialise / unserialise functions here http://www.phpguru.org/
[eluser]narkaT[/eluser]
[quote author="darrenm" date="1228163572"]Ok, I was being lazy. Seems to be as simple as: Code: $route['productsearch/(.)+'] = "productsearch/listing/$1"; nearly Code: $route['productsearch/(.+)'] = "productsearch/listing/$1"; your regex would only "remember" the last char in the URI |
Welcome Guest, Not a member yet? Register Sign In |