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

#1
[eluser]feri_soft[/eluser]
I have a default controller set to products.

and i have this code for pagination:

Code:
class Products extends Controller
{

    function __construct()
    {
        parent::Controller();

    }

    function index()
    {
        
        $this->load->library('pagination');
        $config['base_url'] = base_url(). 'products/';
        $config['total_rows'] = $this->db->count_all('products');;
        $config['per_page'] = '1';
        $this->pagination->initialize($config);
        
        $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:
Code:
$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:
Code:
$config['base_url'] = base_url(). 'products/index/';
and
Code:
$this->uri->segment(2)
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!

#2
[eluser]unosoft[/eluser]
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.

hth
Kumar Bhogaraju

#3
[eluser]feri_soft[/eluser]
I didnt quite undestand but i think the function doesnt need a parameter. I get the number by:
$this->uri->segment(2)

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

#4
[eluser]gunter[/eluser]
so it does not work if you call the page products/
does it work if you add a parameter? products/11

#5
[eluser]feri_soft[/eluser]
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.

#6
[eluser]gunter[/eluser]
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  


Users browsing this thread:
1 Guest(s)


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