2

我正在为我的网站开发分页功能我正在使用Codeigniter,但我不断收到一条错误消息,我无法修复它让我头疼:D 有人可以看看我的代码并告诉我哪里出错了。我只是一个大人物。

错误是Undefined property: CI_Loader::$pagination,也是Fatal error: Call to a member function create_links() on a non-object in C:\....tnx 为您提供帮助

view.php

<!doctype html>
<html>
    <head>

        <meta charset=utf-8>
        <meta name=description content="">
        <meta name=viewport content="width=device-width, initial-scale=1">
        <title>Untitled</title>
        <link rel=stylesheet href="css/style2.css">
        <link rel=author href="humans.txt">

     </head>
   <body>


            <h1>Answer</h1>
            <?php if (isset($records)) : foreach($records as $row) : ?>

      <div = 'container'>
         <!--pagination -->
         <?php echo $this->pagination->create_links(); ?>

          <ul>
              <h1><?php  echo  $row->question; ?></h1>
             <li><?php  echo  $row->answer1; ?></li>
               <li><?php  echo  $row->answer2; ?></li>
               <li><?php  echo  $row->answer3; ?></li>
               <li><?php  echo  $row->answer4; ?></li>
               <li><?php  echo  $row->answer5; ?></li>
               <li><?php  echo  $row->answer6; ?></li>
          <ul>
       </div>
          <?php endforeach; ?>
          <?php else : ?>
          <h2>no records were returned</h2>
          <?php endif; ?>
    </body>
</html>


控制器:

<?php

class Survay extends CI_Controller{

    function index()
    {
        $data = array(
            'question' => $this->input->post('question'),
            'answer1' => $this->input->post('answer1'),
            'answer2' => $this->input->post('answer2'),
            'answer3' => $this->input->post('answer3'),
            'answer4' => $this->input->post('answer4'),
            'answer5' => $this->input->post('answer5'),
            'answer6' => $this->input->post('answer6'),
        );


        if($query = $this->membership_model->get_records())
        {
            $data['records'] = $query;
        }

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

    }



    function page()
    {
        //pagination
        $this->load->library('pagination');

        $config['base_url'] = 'http://localhost/admin/index.php/survay';
        $config['total_rows'] = $this->db->get('save_survay')->num_rows();
        $config['per_page'] = 1;
        $config['num_links'] =20;

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

        $data['records'] = $this->db-get('save_survay', $config['per_page'], $this->uri->segment(3));
        $this->load->view('survay_view', $data);
    } 
}
?>
4

2 回答 2

4

在您的控制器中,$this->load->view...在行之前,您应该这样做:

$data['pagination'] = $this->pagination->create_links();

在视图中,替换echo $this->pagination->create_links()

echo $pagination;

更新

资料来源:见下面 Jeemusu 的评论

我错过了这部分,您在两个控制器方法中使用相同的视图,并且您没有在一个视图中添加分页。

echo $pagination;因此,您应该添加以下内容,而不仅仅是添加:

// check if $pagination variable is existing
if (isset($pagination))
{
    echo $pagination;
}
于 2013-02-14T07:42:58.627 回答
0

您需要自动加载分页库...仅将其加载到函数中是行不通的。

于 2015-09-11T07:49:24.800 回答