CodeIgniter Forums
[SOLVED] query /w pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] query /w pagination (/showthread.php?tid=40490)



[SOLVED] query /w pagination - El Forum - 04-10-2011

[eluser]predat0r[/eluser]
Is it possible to pass a variable/string through an uri segment to a controller, to modify a query?

What I want to do, if someone clicks on "x category" anchor link in my blog, I want to filter the query (my posts), with pagination remain working.

Example link:

anchor('site/posts/2', '') - where 2 is the category_id

How to mix the category param and pagination numbers?

Thank you


[SOLVED] query /w pagination - El Forum - 04-10-2011

[eluser]oppenheimer[/eluser]
Have you looked at $this->uri->segment(n) to pull segments from the URL? For example:
Code:
$category = $this->uri->segment(3);

Then you can filter your data for that category. You may need to change the number 3 to fit your specific URL.


[SOLVED] query /w pagination - El Forum - 04-10-2011

[eluser]micflan[/eluser]
When setting the base_url of the pagination class in the controller you can first check for the existence of the category number.

Code:
$config['base_url'] = 'http://example.com/index.php/site/posts/';
if ($cat_id) $config['base_url'] .= $cat_id . '/';

$this->pagination->initialize($config);



[SOLVED] query /w pagination - El Forum - 04-10-2011

[eluser]predat0r[/eluser]
Thanks, bit same as micflan solution I set a default value for category, and put it to base_url config, and to segment 3, and pagination to segment 4.
So now it works!