Welcome Guest, Not a member yet? Register   Sign In
Nettuts CI Day 7 - Pagination Problem
#1

[eluser]domoench[/eluser]
Hi All,

I'm working through the Nettuts Day 7 Tutorial, and the pagination links are not showing up when I load my view.

My code is as follows:

Controller: site.php
Code:
<?php

class Site extends CI_Controller
{
    function index()
    {
        $this->load->library('pagination');
        
        $config['base_url'] = base_url() . 'site/index/';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        
        $this->pagination->initialize($config);
        
        $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
        $this->load->view('site_view', $data);

    }
}

View: site_view.php
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;

&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;title&gt;Title&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    <div id="container">
        <h1>Super Pagination With CodeIgniter</h1>
        &lt;?php echo $this->pagination->create_links(); ?&gt;
    </div>
&lt;/body&gt;

&lt;/html&gt;

My Setup:
- config.php: Set my base url- 'http://localhost/ci_day7/index.php'
- database.php: Set my hostname, username, password, and database db variables.
- autoload.php: loaded 'database' library, and 'url' helper

Does anything above stick out as a reason why the <h1> would display in the view, but the $this->pagination->create_links() line does not?
#2

[eluser]InsiteFX[/eluser]
Your missing the line below!
Code:
$config['uri_segment'] = 3;

InsiteFX
#3

[eluser]domoench[/eluser]
Thanks for the response Insite - I plugged in that line, but it had no effect. My controller now reads as follows:

Code:
&lt;?php

class Site extends CI_Controller
{
    function index()
    {
        $this->load->library('pagination');
        
        $config['base_url'] = base_url() . 'site/index/';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        $config['uri_segment'] = 3;
        
        $this->pagination->initialize($config);
        
        $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
        $this->load->view('site_view', $data);
    }
}

Any other problems visible?

Thanks.
#4

[eluser]DanTheMan[/eluser]
Hi domoench,

This is probably something you have checked however; if you have not got more records in the database (in your case 10) then if I am correct it will not output any of the pagination links. It only outputs above your limit.

Dan
#5

[eluser]InsiteFX[/eluser]
Pagination with CodeIgniter

InsiteFX
#6

[eluser]domoench[/eluser]
DanTheMan - That was it! I thought I had checked for that, but I recounted and I had created exactly 10 and no more. When I added a few more posts in my database the pagination links magically appeared.

InsiteFX - Thanks for the link, looks very in-depth and slightly different in approach from the nettuts video I'm working through so I'm sure giving it a going over will help me solidify this stuff.

Thanks all!
#7

[eluser]DanTheMan[/eluser]
domoench,

No problem! Im glad I could help. I have have to double check a couple of times in testing before thinking it wasn't working when it was.

GL with the rest of your site.
Dan




Theme © iAndrew 2016 - Forum software by © MyBB