Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] query /w pagination
#1

[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
#2

[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.
#3

[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);
#4

[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!




Theme © iAndrew 2016 - Forum software by © MyBB