2

DB から返された結果をページ分割しようとしています。しかし、URI からオフセットを取得しようとすると:

questions/search?content=foobar/4

/4オフセットである必要がありますが、$_GET値に割り当てられています。

これは、コントローラーのメソッド全体です。

http://pastebin.com/QFJddMDJ

$results = $this->question->search_results_count($content);
$this->load->library('pagination');
$config['total_rows'] = count($results);
$offset = $this->uri->segment(3);
if ($offset == false) $offset = 0;
$config['full_tag_open'] = '<ul class="pages">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li><a  class="active">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '<li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = '>>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['per_page'] = 1;
$config['uri_segment'] = 2;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['suffix'] = '?content='.$content;
$config['base_url'] = base_url().'questions/search/';
$this->pagination->initialize($config);
4

1 に答える 1

12

ご存じのとおり、URI はそのようには機能しません。クエリ文字列は末尾 (または#ハッシュ フラグメントの前) にある必要があります。このクエリ文字列:

questions/search?content=foobar/4

意味$_GET['content'] = 'foobar/4';

ページネーション URL を次のように変更する必要があります。

questions/search/4/?content=foobar

4の/あとはオプションもあります。

ページネーションからクエリ文字列を削除し、$config['base_url']代わりにビュー内のリンクに追加する必要があります。これには、悲しいことに、ページネーション クラスのハッキングが含まれます...

または、次の文書化されていない機能を試してください。

// After loading the pagination class
$this->pagination->suffix = '{YOUR QUERY STRING}';

$config['suffix'] = '{YOUR QUERY STRING}';または、クラスをロードする前に構成に追加するだけです。これにより、クエリ文字列がすべてのリンクに自動的に追加されますhref

構成領域へのいくつかの調整も必要でした:

// Make sure to encode these
// $config['first_link'] = '<<';
$config['first_link'] = '&lt;&lt;';
// $config['last_link'] = '>>';
$config['last_link'] = '&gt;&gt;';

$offset = $this->uri->segment(3);
// Default URI segment is 3, and it's what you use above. Remove this.
// $config['uri_segment'] = 2;

// This should be FALSE (default). Remove it.
// $config['page_query_string'] = TRUE;

// This should be FALSE (default) if you're
// using the URI segment as your OFFSET. Remove it.
// $config['use_page_numbers'] = TRUE;

// Add your query string
$config['suffix'] = '?content='.$content;
$config['base_url'] = base_url().'questions/search/';
$this->pagination->initialize($config);
于 2012-05-08T19:49:06.747 に答える