0

こんにちは、Web プロジェクトでページネーション機能を構築しようとしています。codeigniter のユーザー ガイドと net tuts のチュートリアルをここにリンクしますが、これらの 2http://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

これらのエラーがどこから来ているのか、どうすれば修正できるのかを理解できません。

コントローラ

<?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();

    }



}



?>
4

1 に答える 1

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);

        }

}

于 2013-03-06T10:08:03.063 に答える