Welcome Guest, Not a member yet? Register   Sign In
Pagination, weird problem?
#1

[eluser]felixk[/eluser]
Hey, I can't get my pagination to work even though I've followed tutorials and the user_guide, I must be too tiered or something.
Here's some code:

Model
Code:
function All($num, $offset)
{
    $this->db->order_by('date', 'desc');
    $this->db->limit($num, $offset);
    $query = $this->db->get('blogg');
    return $query;
}

Viewe
Code:
<?php foreach($query->result() as $row): ?>
            &lt;?php echo $row->title; ?&gt; <br />
        &lt;?php endforeach; ?&gt;
        &lt;?php echo $this->pagination->create_links(); ?&gt;

Controller
Code:
function index()
    {
        $data['title'] = "Fabriken Fredag | Blogg";
        $this->load->library('pagination');

        $config['base_url'] = base_url().'blogg';
        $config['total_rows'] = $this->db->count_all_results('blogg');
        $config['per_page'] = 4;
        $config['uri_segment'] = 2;
        $this->pagination->initialize($config);
        $uri = $this->uri->segment(2);        
        //DB
        $data['query'] = $this->blogModel->All($config['per_page'], $uri);        
        $this->load->view('blogg_view', $data);
    }

Thankful for quick replies!

//Felix Karlsson
#2

[eluser]jrtashjian[/eluser]
It might be an issue with your $config['base_url'] setting. Try using site_url() instead of base_url(). Also, count the number of segments after index.php and add 1. That is the segment you want for your $config['uri_segment'].

Let me know how that works out for you!
- JR
#3

[eluser]felixk[/eluser]
No it doesn't work :S

The error after clicking this link: http://localhost/jobb/Fredag/index.php/blogg/4

Quote:404 Page Not Found
The page you requested was not found.

I've changed to site_url(), and the uri_segment should be set to 2, right?
#4

[eluser]jrtashjian[/eluser]
I am assuming 'blogg' is the controller? You need to specify the method you are using in your controller. Right now, Codeigniter is looking for the method '4' in controller 'blogg'. Set you url like so:
Code:
site_url('/blog/index/');
Replace 'index' with the method you are using. The uri_segment will be 3 now.
#5

[eluser]felixk[/eluser]
Oh, of cource Tongue Thanks!

Now I don't get an error message, but it still don't work properly. Sad
When I click "2", the url is http://localhost/jobb/Fredag/index.php/blogg/index/4,
but the entries showing are still the same as before.

No matter what i change the 3rd segment to, the output is the same.
#6

[eluser]jrtashjian[/eluser]
Is the offset for your function $this->blogModel->All() set to the correct URI as well?
Code:
$this->blogModel->All($config['per_page'], $this->uri_segment(3));
#7

[eluser]felixk[/eluser]
I'm fucking retarded, sorry ... haha

Thank's a lot Smile
#8

[eluser]jrtashjian[/eluser]
haha. I do it all the time too! Glad it's finally working!




Theme © iAndrew 2016 - Forum software by © MyBB