2013-02-14 211 views
0

大家好有人可以解釋一下這劑做分頁功能無法正常工作

$this->uri->segment()); 

其分頁我功能的一部分,我無法弄清楚,爲什麼我需要它,如果有什麼來取代它。它在我的腳本中導致錯誤。感謝你的幫助。另外即時通訊新的codeigniter和php的plys試圖讓我提前簡單地形成tnx。

錯誤消息

甲PHP錯誤遇到

嚴重性:注意

消息:試圖獲得非對象的屬性

文件名:視圖/ survay_view.php

行號:31

這裏是我爲我的分頁功能,所有的代碼

//pagination 
     function page() 
      { 

      $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'] =10; 

      $this->pagination->initialize($config); 
      //print_r($this->uri->segment());die; 

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

      } 
    } 
+0

這意味着uri不是一個有效的對象,所以你不能在其上調用成員函數'segment'。找出爲什麼沒有設置該成員。您可以嘗試使基本網址看起來很正常。 – noelicus 2013-02-14 10:34:54

+0

我應該在哪裏開始查看哪些成員沒有設置,並且可以擴展更多關於如何使基礎URL看起來正常? – 2013-02-14 10:42:16

+0

uri段應指向包含頁碼的url中的參數。 – cartina 2013-02-14 10:59:11

回答

1

變量$this->uri->segment();是指一個特定的URI段。

因此,舉例來說,如果你有一個網址/網頁/視圖/ 1

如果你沒有迴音$this->uri->segment(2);它會返回「視圖」。

有關詳細信息,請參見http://ellislab.com/codeigniter/user-guide/libraries/uri.html

+0

你有什麼建議如何解決我得到的錯誤?我閱讀Codeigniter用戶指南鏈接你發給我我明白它的作用,但貓仍然找出如何解決這個錯誤。 – 2013-02-14 10:58:02

+0

我不確定你的URL結構,但你需要改變'$ data ['records'] = $ this-> db-> get('save_survay',$ config ['per_page'],$ this - > uri-> segment());'包含正確的段,IE根據您的網址,可能是$ this-> uri-> segment(2)或$ $ this-> uri-> segment(3)'。如果你print_r($ data ['records'])',它顯示什麼? – 2013-02-14 12:53:07

+0

它會顯示錯誤 甲PHP錯誤遇到 嚴重性:警告 消息:缺少參數1 CI_URI ::段(),被稱爲在C:\瓦帕\ WWW \管理員\應用\控制器\ survay.php上第43行和定義 文件名:core/URI.php 行號碼:341 – 2013-02-14 13:23:50

0

this $ this-> uri-> segment();實際上是從url中獲取值。就像$ _GET []一樣。 查看http://ellislab.com/codeigniter/user-guide/libraries/uri.html瞭解詳情。

+0

你有什麼建議如何解決我得到的錯誤?我閱讀Codeigniter用戶指南鏈接你發給我我明白它的作用,但貓仍然找出如何解決這個錯誤。 – 2013-02-14 10:57:37

+0

錯誤來臨$ this-> db->我想。因爲我認爲這個函數在你的控制器中,$ this-> db-> get this是模型的屬性。未定義的對象錯誤即將到來。 – ripa 2013-02-14 11:01:22

+0

我遵循的教程在控制器中使用了$ this-> db-> get,並且沒有任何錯誤地爲他工作,如果你有更多的建議,這將不勝感激 – 2013-02-14 11:06:19