douzi1117 2013-02-14 07:17
浏览 78
已采纳

未定义的属性:CI_Loader :: $ pagination

im working on a pagination function for my site i am using Codeigniter and i keep getting an error message that i cant fix it makes my head hurt :D can some one take a look at my code and tell me where i have went wrong. im only a bigginer.

the error is Undefined property: CI_Loader::$pagination and also Fatal error: Call to a member function create_links() on a non-object in C:\.... tnx for ur help

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>


Controller:

<?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);
    } 
}
?>
  • 写回答

2条回答 默认 最新

  • douwen5246 2013-02-14 07:42
    关注

    In your controller, before the $this->load->view... row you should do this:

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

    and in the view, replace echo $this->pagination->create_links() with

    echo $pagination;
    

    Update

    Source: See Jeemusu's comment below

    I missed the part, that you're using the same view in two controller methods, and you are not adding pagination in one view.

    so, instead of just adding echo $pagination; you should add this:

    // check if $pagination variable is existing
    if (isset($pagination))
    {
        echo $pagination;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示