分页没有工作未解决的错误

时间:2013-03-06 09:59:07

标签: php codeigniter pagination

大家好我想尝试在web项目中构建一个分页功能我在codeigniter上使用了用户指南,这里有一个关于net tuts的教程是链接http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-day-7-pagination/ 但我不断收到这些错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$pagination

Filename: views/result_view.php

Line Number: 41

 Fatal error: Call to a member function create_links() on a non-object in C

无法想出这些错误,他们来自哪里以及我如何解决这些错误可以帮助我,这是我的cmv:

控制器

<?php

class Result_controller extends CI_Controller{

    function getall(){

        $this->load->model('result_model');
        $data['query'] = $this->result_model->result_getall();
       // print_r($data['query']); die();
        $this->load->view('result_view', $data);

        }

        function pagination()
        {

            $this->load->library('pagination');

            $config['base_url'] = 'result_controller/pagination';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 5;
        $config['num_links'] = 3;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);

        $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));

        $this->load->view('result_view', $data);




        }

查看

 <table border="1">


  <tr>
     <th>Name</th>
     <th>Second Name</th>
     <th>Phone</th>
     <th>Email</th>
     <th>Answer</th>
     <th>Comment</th>
 </tr>
  <?php foreach ($query as $row): ?> 
 <tr>

     <td><?php echo $row->name; ?></td>
     <td><?php echo $row->second_name; ?></td>
     <td><?php echo $row->phone; ?></td>
     <td><?php echo $row->email; ?></td>
      <td> <?php echo $row->answerA;?>
      <?php echo $row->answerB;?>
      <?php echo $row->answerC;?></td>
     <td><?php echo $row->comment;?><br></td>

 </tr>

      <?php endforeach; ?>

     </table>  
     <?php echo $this->pagination->create_links(); ?>

模型

<?php

class Result_model extends CI_Model{

    function result_getall(){

         return $this->db->select('*')
                         ->from('tblanswers, credentials')
                         ->get()
                         ->result_object();

    }



}



?>

1 个答案:

答案 0 :(得分:1)

从视图中删除此行

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

然后粘贴这个

<?php echo $pagination ?>

修改

而不是使用分页功能将分页代码放在getall()函数中,如下所示:         

class Result_controller extends CI_Controller{

    function getall(){

        $this->load->model('result_model');
        $data['query'] = $this->result_model->result_getall();
        // print_r($data['query']); die();


        $this->load->library('pagination');

        $config['base_url'] = 'result_controller/getall';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 5;
        $config['num_links'] = 3;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
        $this->load->view('result_view', $data);

        }

}