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

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

Have you looked at $this->uri->segment(n) to pull segments from the URL? For example:
$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.

When setting the base_url of the pagination class in the controller you can first check for the existence of the category number.

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


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