• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination help

I have a default controller set to products.

and i have this code for pagination:

class Products extends Controller

    function __construct()


    function index()
        $config['base_url'] = base_url(). 'products/';
        $config['total_rows'] = $this->db->count_all('products');;
        $config['per_page'] = '1';
        $query = $this->db->get('products', $config['per_page'], $this->uri->segment(2));
        $data['products'] = $query->result_array();
        $data['pagination'] = $this->pagination->create_links();
        $template['title'] = "asdasdasdasdasd";
        $template['description'] = "asdasdasdasdasd";
        $template['keywords'] = "asdasd, asdasd, asdasdasd, asdasd";
        $template['left'] = $this->load->view('left', $data, true);
        $template['content'] = $this->load->view('products', $data, true);
        $this->load->view('container', $template);

And in routes i have the following:
$route['products/:num'] = "products/index";

Its not working at all i get 404 not found error. But when i remove the route and change the products to:
$config['base_url'] = base_url(). 'products/index/';
al is working fine.

Please tell me whats the problem. I have checked the user guide but nothing on this issue was posted. I have to find a solution on this. Thanks!

When you specify route like below, are you not specifying that any number that follows products in the URL, pass it as a parameter to the index function?
$route['products/:num'] = "products/index";

But your index function has no parameters. I believe thats why you are getting 404 error.

Kumar Bhogaraju

I didnt quite undestand but i think the function doesnt need a parameter. I get the number by:

Any suggestions? IS it possible that to be a bug only with the index function?

so it does not work if you call the page products/
does it work if you add a parameter? products/11

NO i mean that if the paging query is set to products/ it doesnt work and if its products/index/ it does.
It adds the parameter itselft like when i click page 2 it shows products/2 and if its with index - products/index/2 but the difference is that the first way its not working and the second it does.

Ok, then I cannot help, I thought that /products don´t work, but products/2 does... that would be because the router needs the :num argument...

then good luck! :coolsmile:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.