2

articleと呼ばれるコントローラーには、データベースからのデータを表示するために使用している次の関数があります。

function get_all(){

  $this->load->library('pagination');
  $config['base_url'] = base_url().'article/get-all';
  $config['total_rows'] = 2; // example
  $config['per_page'] = 1;
  $config['num_links'] = 20;
  $config['full_tag_open'] = '<div class="pagination" align="center">';
  $config['full_tag_close'] = '</div>';

  $this->pagination->initialize($config);

  $this->load->model('mod_articles');
  $data['records']= $this->mod_articles->get_articles_this_year($config['per_page'],$this->uri->segment(3));

  $this->load->view('view_article_list',$data);
}

通常、関数に到達するためhttp://localhost/article/get_allの URL は: ですが、URL を次のようにするためhttp://localhost/article/get-allに、config/route.php に次の行を追加しました。

 $route['article/get-all'] = "article/get_all";

正常に動作していますが、ページネーション リンクをクリックして次のページに移動すると、404 Page Not Foundと表示されます。

URI ルーティング ワイルドカードの適切な使用方法を教えてください。

編集

URLにインデックスが表示されないように、config/route.phpに次のものもあります

 $route['article/(:any)'] = "article/index/$1";

上記の行を削除すると、ページネーションが機能します。

4

2 に答える 2

3

ページネーション クラスは、余分な URI セグメントをリンクに追加しますか? たとえば、次のようになります。

/article/get-all/page/5

その場合、次のような 2 つのルートを設定する必要があります。

$route['article/get-all'] = "article/get_all";
$route['article/get-all/(:any)/(:any)'] = "article/get_all/$1/$2";
于 2013-02-19T23:45:00.933 に答える