Ive recently started using CodeIgniter as I was searching for a very lightweight framework and it seemed to come up as a top choice.
I am new to the whole MVC thing, enjoying it but am stuck with something which seems very simple.
I am coding a CMS and need a way to filter, sort and paginate the results. I am used to doing it with querystrings, so I would have something along the lines of:
articles.php?order=title&sort=desc&filter=articletitle&page=5
I have no idea how I would go about doing this in CI so I just turned on the EnableQueryStrings in the config and it works fine, but i am getting the feeling its probably not the most elegant solution.
I suppose I could have
index.php/articles/index/order/title/sort/desc/filter/articletitle/page/5
but to me this seems very inflexible, what if for example i dont need to sort, how would i make sure i am looking at the correct uri segment?
any ideas?
Have you tried implementing the _remap function? It will redirect all queries to the controller to that function allowing you to implement as many (or as few) of those as you like.
You could then do something like this:
class Articles extends Controller
{
// Note: No need for a "order" or even an "index" function!
public function _remap()
{
$assoc = $this->uri->uri_to_assoc( 4 );
/* $assoc is now
array( "order"=>"title",
"sort"=>"desc",
"filter"=>"articletitle",
"page"=>5); */
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With