Zeljko Kovacevic
Zeljko Kovacevic

Reputation: 73

CodeIgniter 404 error page not found in pagination

I have problem making CodeIgniter pagination when i click on link i get 404 page not found my code in controler is

class Records extends CI_Controller 
{
    public function index()
    {   
        $this->load->library('pagination');
        $config['base_url']= 'localhost/records';
        $config['total_rows']= $this->db->get('pages')->num_rows;
        $config['per_page']= 2;
        $config['num_links']= 5;
        $this->pagination->initialize($config);
        $data['query'] = $this->db->get('pages',$config['per_page'],$this->uri->segment(2));



        $this->load->view('view_header');
        $this->load->view('includes/nav_home');
        $this->load->view('view_list', $data);
        $this->load->view('view_footer');

}

i tried diffrent uri segments, but still no result. ? I am writing code in right way. my base_url is empty in config file?

in view my code is

<?php
echo $this->session->flashdata('item');
echo '<h4>Lista podataka</h4>';

foreach ($query->result() as $q):

?>
<a href="/z/update/grab/<?php echo $q->id;?>/<?php echo $q->info; ?>"><?php echo $q->info . br() . br()?></a>
<?php 
endforeach;

echo $this->pagination->create_links();
?>

Upvotes: 0

Views: 1627

Answers (4)

md asif rahman
md asif rahman

Reputation: 389

Base url in must be contain the same function that is used to fetch data it means $config['base_url']='localhost/project/records/index';

Upvotes: 0

Varun Victor
Varun Victor

Reputation: 100

Base Url needs to be

$config['base_url']= 'records/index';

Upvotes: 0

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

try may be change uri segment

    $this->load->library('pagination');
    $config['base_url']= base_url().'/records/index'; 
    $config['total_rows']= $this->db->get('pages')->num_rows;
    $config['uri_segment'] = 3;
    $config['per_page']= 2;
    $config['num_links']= 5;
    $this->pagination->initialize($config);
    $data['query'] = $this->db->get('pages',$config['per_page'],$this->uri->segment(3));

For more follow :- pagination in codeigniter

Upvotes: 0

CodeSlayer
CodeSlayer

Reputation: 1327

As far I understand you can't access your next page pagination? So I think it's because of this $config['base_url']= 'localhost/records';

you should put your complete url(including the controller name and function name), so it should be

$config['base_url']= 'localhost/records/index.php/controller_name/function';

and in your uri segment should $this->uri->segment(3)

Upvotes: 2

Related Questions