2011-09-28 68 views
1

我仍在使用CodeIgniter框架進行學習。今天,我發現自己面臨着分頁問題。CodeIgniter中url中的2個變量時出現分頁錯誤

事實上,我可以通過一個id訪問數據,這需要url中的變量和另一個分頁。

這是我的控制器foo中的foos_by_day函數(這不是真名,它只是一個例子),它在特定的一天返回一個foos數組。 這些foos來自我的數據庫,並通過名爲model_foos的模型轉到我的控制器get_foos_by_day($ day)。

function foos_by_day($day) { 
    $configpages['base_url'] = 'http://www.exemple.com/ci/index.php/foo/foos_by_days/'.$foo."/"; 
    $configpages['total_rows'] = count($this->model_foos->get_foos_by_day($foo)); 
    $configpages['per_page'] = 10; 
    $config['uri_segment'] = 4; 

    $this->pagination->initialize($configpages); 
    $data['foos'] = $this->model_foos->get_foos_by_day($jour, (int)$this->uri->segment(4), $configpages['per_page']); 

    $this->load->view('foo_view.php', $data); 
} 

這是我的看法:

<?php foreach ($foos as $element): ?> 
    <div> 
    Name of the foo : <?=$element->name?><br /> 
    Date of the foo : <?=$element->date?><br /> 
    </div> 
<?php endforeach; ?> 
<?php echo $this->pagination->create_links(); ?> 

我得到一些奇怪的事情在我看來,當我輸入:http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/

我32個FOOS的編號開始於(最後一頁) 。它每頁正確顯示10個foos,但是當我點擊另一個頁面時,所選頁面保持第四個。 此外,頁碼後面的鏈接給了我下面的語句:

<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/">First</a> 
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/20">&lt;</a> 
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/10">2</a> 
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/20">3</a> 
<strong>4</strong> 

所以說:沒事,然後20,10和20(再次)。簡而言之,分頁中存在一個錯誤。

你有沒有遇到過這種情況(帶有分頁錯誤)?如果是這樣,你是如何解決它的? 您認爲我應該如何繼續尋找定期分頁?

在此先感謝。

P.S. :我沒有刪除index.php文件,但我已經學會了在其他CodeIgniter上做。

回答

1

變化 $config['uri_segment'] = 4;$configpages['uri_segment'] = 4;

+0

哇!你是對的!我怎麼錯過這樣的事情?!非常感謝! 現在它工作:) – Dacobah

相關問題