CodeIgniter Forums
routes rewrite - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: routes rewrite (/thread-34766.html)



routes rewrite - El Forum - 10-08-2010

[eluser]sojic[/eluser]
I need url structure: /class.method/param1/value1/param2/value2/format/formatValue

Any hint how to handle this?


routes rewrite - El Forum - 10-08-2010

[eluser]WanWizard[/eluser]
I think this will work:
Code:
$route['(.+?)\.(.+?)/(.*)'] = '$1/$2/$3';



routes rewrite - El Forum - 10-08-2010

[eluser]sojic[/eluser]
I need something else

I need restfull url /class.method/param1/value1/param2/value2 so I need to rewrite into param1=value1&param2=value2 or...

function method($param1, $param2)

So... what if somebody call /class.method/param2/value2/param1/value1

Here is example

user.list/category/software/page/2 is same with
user.list/page/2/category/software


routes rewrite - El Forum - 10-08-2010

[eluser]techgnome[/eluser]
Maybe it's just me... but people shouldn't just be able to call methods any old way they want... there has to be some kind of rule that needs to be enforced at some point. Otherwise you'll end up driving yourself with endless what ifs... I've seen it happen... never pretty. Even a car enforces rules at some point, you can't just shift gears unless first disengaging the clutch.

-tg


routes rewrite - El Forum - 10-08-2010

[eluser]pickupman[/eluser]
How about leaving your parameters out of the arguments for your method. Call them from inside the method by using:
Code:
function method(){
  $params = $this->uri->uri_to_assoc();
  //or
  $params = $this->uri->ruri_to_assoc(); //for routed uri
}

Now you've got a set of key=>value pairs to use to your liking.


routes rewrite - El Forum - 10-09-2010

[eluser]kainadolf[/eluser]
It is likely to other variable or function definition. I could see from my code provides an example, you should want to use bases, in addition to showing you the route it may be a route map to the other route. You can easily replace the "MyModule's / mycontroller / ([0-9] +)" to "([a, miscellaneous - Z of ]+)/([ a miscellaneous - Z of ]+)/([ 0-9] +) "and then map 1 to module 2 to the controller.