• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick regex routing question

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:

/productsearch/(varying*number*of*segments) = /productsearch/listingfunction/(*everything*)

Can anyone help me out with the regex specifics?

many thanks.

Ok, I was being lazy. Seems to be as simple as:

$route['productsearch/(.)+'] = "productsearch/listing/$1";

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


[quote author="darrenm" date="1228163572"]Ok, I was being lazy. Seems to be as simple as:

$route['productsearch/(.)+'] = "productsearch/listing/$1";

nearly Wink

$route['productsearch/(.+)'] = "productsearch/listing/$1";

your regex would only "remember" the last char in the URI Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.