本文介绍了未定义属性:CI_Loader :: $ pagination的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Codeigniter 为我的网站工作的分页功能,我不断收到一个错误消息,我无法修复它使我的头受伤:D可以有人看看我的代码并告诉我我在哪里错了。

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.

错误是未定义的属性:CI_Loader :: $ pagination 以及致命错误:调用C:\ ....上的非对象上的成员函数create_links()。 tnx for ur help

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


推荐答案

> $ this-> load-> view ... 行您应该这样做:

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

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

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

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

echo $pagination;

更新

资料来源:请参阅Jeemusu的下面的注释

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.

因此,您应该添加此对话框,而不是只添加 echo $ pagination;

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

// check if $pagination variable is existing
if (isset($pagination))
{
    echo $pagination;
}

这篇关于未定义属性:CI_Loader :: $ pagination的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:01