2013-02-14 85 views
2

即時通訊工作在我的網站的分頁功能我正在使用Codeigniter和我不斷收到一條錯誤消息,我不能修復它讓我頭疼:D有人可以看一看在我的代碼中告訴我我哪裏出錯了。我只是一個大膽的人。

誤差Undefined property: CI_Loader::$paginationFatal 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

在你的控制器中,$this->load->view...行之前,你應該這樣做:

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

和看法,與

echo $pagination; 

更新替換echo $this->pagination->create_links()

來源:請參見下面

我錯過了部分Jeemusu的評論,您使用了同樣的看法有兩種控制器方法,並且您不在一個視圖中添加分頁。

如此,而不是僅僅增加echo $pagination;你應該補充一點:

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

因爲'index()'和'page()'方法都使用了相同的視圖'survay_view',所以你可能需要在'if(isset($ pagination)){}'但分頁數據僅在page()方法中設置。 – Jeemusu 2013-02-14 08:09:04

+0

tnx爲你的幫助,但你可以擴大更多的你的評論我是一個noob上的PHP :) tnx – 2013-02-14 08:26:34

+0

@Jeemusu:這是真的 – beerwin 2013-02-14 08:32:02

0

您需要自動加載分頁庫...只是加載它的功能是不行的。