現在、Pyrocmsのページで製品一覧を表示しています。プラグインを使用して、db テーブルから製品を取得し、ページネーションを使用したいリストとして表示しますが、その使用方法とどこから始めればよいかわかりません。チュートリアルを知っている人はいますか、またはいくつかの提案がありますか?
質問する
1808 次
2 に答える
1
ページネーション ライブラリをロードしたり、初期化したりする必要はありません。通常の codeigniter で行うのとは少し異なります。また、codeigniter のページネーション クラスで行う方法を確実に使用できます。
私は通常、ページネーションのためにこれを行います。
コントローラーでこれを使用します
....
// Create pagination links
$total_rows = $this->products_m->count_all_products();
$pagination = create_pagination('products/list', $total_rows);
//notice that product/list is your controller/method you want to see pagination there
// Using this data, get the relevant results
$params = array(
'limit' => $pagination['limit']
);
$this_page_products = $this->product_m->get_all_products($params);
....
//you got to pass $pagination to the view
$this->template
->set('pagination', $pagination)
->set('products', $this_page_products)
->build('products/view');
明らかに、あなたのモデルでは、products_m
これがあなたの関数になるという名前のモデルがあります。関数もget_all_products
構築できると確信していますcount_all_products()
private function get_all_products($params){
//your query to get products here
// use $this->db->limit();
// Limit the results based on 1 number or 2 (2nd is offset)
if (isset($params['limit']) && is_array($params['limit']))
$this->db->limit($params['limit'][0], $params['limit'][1]);
elseif (isset($params['limit']))
$this->db->limit($params['limit']);
//rest of your query and return
}
ビューforeach
で、渡された$products
変数を使用し、ページネーション リンクを表示するには、ビューでこの行を使用する必要があります
<?php echo $pagination['links'];?>
私は自分の作品でこれを使用しています。
于 2012-08-24T00:25:27.797 に答える
0
Pyrocms は codeigniter フレームワークを使用しました。このコードはモジュールの場合は完全に機能しますが、プラグインでこれを試したことはありませんが、それでも試すことができます。
コントローラーにページネーション ライブラリをロードする
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
ビューでこのコードを使用して、リンクを生成します
echo $this->pagination->create_links();
于 2012-08-23T08:07:46.190 に答える