0

I create urls using the following pattern:

www.website.com/page/1/sort/login

When I wanna change, for example, sorting method, I simply add the new one to the end of the url:

www.website.com/page/1/sort/login/sort/email

And replace the old one in the controller (string replaces etc...). So, clicking the link with URL from above would:

  1. Redirect to www.website.com/page/1/sort/login/sort/email
  2. Replace sorting by login with sorting by email IN CONTROLLER

The problem is that the link doesn't change of course - it contains double sort elements.


What I want to achieve is to change the route in the URL from controller's method after the redirect. Is this possible?

khernik
  • 2,059
  • 2
  • 26
  • 51
  • Isn't it easier to make a function sort() that behaves differently depending on the parameter that you send to it ? So in your controller you should have a function sort ( $sort_parameter ) { //Do stuff } Then you could change the url, to www.website.com/page/1/sort/SORT_PARAMETER Just load the uri helper, and extract the variable from the URL – wick3d Jul 28 '14 at 10:10
  • Sort was just an example - I have a lot of different parameters here. So it could be like www.localhost.com/page/1/sort/login/order/asc/active/true...where the whole string after .com is one get parameter. – khernik Jul 28 '14 at 10:13
  • And when I add new parameter, I just add it to the end of the URL in twig, and then replace it correctly in the controller. – khernik Jul 28 '14 at 10:15
  • Seems to me that you have a function that is working with a "big" number of parameters. Try passing an array of parameters, with $this->uri->uri_to_assoc(n). Here's the documentation: http://ellislab.com/codeigniter/user-guide/libraries/uri.html Then just get the proper values and your funcyion will be working like a charm ;] – wick3d Jul 28 '14 at 10:40
  • @wick3d This is Symfony, not CodeIgniter. Can you please post the content of your controller and route definition? How are you processing this query? – Touki Jul 28 '14 at 12:18
  • @Touki Aw balls! Sorry mate I completely thought this was CI. Can't really help you with Symphony, but after a short research I found this little question here on stackoverflow regarding how to pass an array in the url - might lead you in the right direction. http://stackoverflow.com/questions/20050460/symfony-generate-url-with-parameter-in-controller and this http://stackoverflow.com/questions/8354634/symfony-2-0-how-to-create-route-with-array-parameters – wick3d Jul 28 '14 at 13:12

0 Answers0