Welcome Guest, Not a member yet? Register   Sign In
Paginate from index function?
#1

[eluser]Corey Freeman[/eluser]
I'm trying to paginate results from the index function of the controller, instead of from a sub function. However, I get a 404 error whenever I click the "next page" links. Help?

Code:
<?php
class Comic extends CI_Controller {
    public function index()
    {
    $this->load->library('pagination');
        $this->load->view('header');
            $this->load->model('comics');
            $per_page = 1;
            $total = $this->comics->count_comics();
            $data['comics'] = $this->comics->get_comics($per_page, $this->uri->segment(2));
            $base_url = base_url().'comic/';
            $config['base_url'] = $base_url;
            $config['total_rows'] = $total;
            $config['display_pages'] = FALSE;
            $config['per_page'] = $per_page;
            $config['uri_segment'] = '2';
            $this->pagination->initialize($config);
            $this->load->view('comic', $data);
        $this->load->view('footer');
    }
}
#2

[eluser]kr1pt[/eluser]
$base_url = base_url().'comic/index/';
#3

[eluser]Corey Freeman[/eluser]
That still produces a 404 error Sad
#4

[eluser]kr1pt[/eluser]
[quote author="Corey Freeman" date="1301182460"]That still produces a 404 error Sad[/quote]

I had same problem. You cannot use pagination index() obviously.
#5

[eluser]isawhat[/eluser]
I think it's your uri_segment, 1 and 2 in the uri_segment are the controller and function, 3 and up would be settings your passing by the url, the pagination class will be the last segment, so unless your passing something else, then the url_segment should be 3.
#6

[eluser]ηυмвєяσηє[/eluser]
u should use 3rd uri_segment


if u dont wanna see function name, u can use routes

like :

Code:
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";
#7

[eluser]Flying Fish[/eluser]
I had the same issue getting 404 pages with pagination using segment_2 on the index function

funny thing is that it started after my upgrade to CI2, worked ok in 1.7

using segment_3 fixed it for me




Theme © iAndrew 2016 - Forum software by © MyBB