Segment-based URL vs Query Strings |
Hi,
I write application and need some help. E.g. the page "Customers" has a lot of rows and I use the filter form on the top of page with fields: "Name","Filial","Status" and so on. I need "track" filtered result when clicking edit item and return to the search page. Yes, I can achieve this with query string like below http://example.com/index.php?c=customers...tus=active But what about segment-based. Is it possible? Thanks!
In most cases, the segment-based alternative to the URL you've supplied would be something like http://example.com/index.php/customers/i...ill/active or http://example.com/index.php/customers/i...tus/active (you could also filter out the index.php with mod_rewrite, if you wished).
Generally, the first format is easier to support, as you would just setup your Customers controller's index() method to accept two arguments (client_name and status), like this: PHP Code: class Customers extends MY_Controller The biggest drawback to this method is that they have to be supplied in a consistent order. If you use the second form (where the name of each section precedes the value, much like the original query string), you can change the order, but you have to spend a little more time mapping the arguments to variables in your controller. The URI class provides a method for getting the URI segments in an associative array from the name/value format called uri_to_assoc().
Thanks for reply. I know about uri_to_assoc.
My problem was in allowed characters in config-file and I am unable to set in the name field value like "Hello World!" as encodeURIComponent does not encode !, ', (, ), and *. My code Code: $('#button-filter').on('click', function() { But suddenly I have found the solution. Just small fix to encodeURIComponent. https://developer.mozilla.org/en-US/docs...IComponent P.S. I am not a coder but I LOVE CI! It's fantastic! :-)
Yes, as long as you pass data through the URL, whether in a query string or as a URI segment, it will be limited to valid URL characters. Otherwise, you would have to pass the data as part of a post (in a form or using something like $.post() in jQuery), which would also mean that users would not be able to use a specific URL to return to the filtered results.
|
Welcome Guest, Not a member yet? Register Sign In |