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?

6
  • 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 Commented Jul 28, 2014 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. Commented Jul 28, 2014 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. Commented Jul 28, 2014 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: ellislab.com/codeigniter/user-guide/libraries/uri.html Then just get the proper values and your funcyion will be working like a charm ;] Commented Jul 28, 2014 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? Commented Jul 28, 2014 at 12:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.