1

これが私のコントローラーです:

class Comment extends CI_Controller {

function article() {
    $this->load->library('pagination');
    $this->load->model('comment_m');
            $id=$this->uri->segment(3);
    $config['base_url'] = 'http://localhost/ci/CodeIgniter_2.1.3/index.php/comment/article/'.$id;
    $config['total_rows'] = $this->db->get('comment_article')->num_rows();
            $config['per_page'] = 5;
    $config['num_links'] = 5;
    $config['full_tag_open'] = '<div id="pagination">';
    $config['full_tag_close'] = '</div>';
    $this->pagination->initialize($config);
            echo $this->uri->segment(4);
            $data['c_review'] = $this->comment_m->getarticle($id, $config['per_page'], $this->uri->segment(4));

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

これが私のモデルです:

class Comment_m extends CI_Model{

function getarticle($id,$limit,$start) {
    $this->db->select('name, content');
    $this->db->from('comment_article');
            $this->db->where('article_id', $id); 
            $this->db->limit($limit, $start);
    $q = $this->db->get();

    if($q->num_rows() > 0) {
        foreach ($q->result() as $c_review) {
            $data[] = $c_review;
        }
        return $data;
    }       

}
}

記事が10個以下(2ページのみ)の場合、ページ付けは正常に機能しますが、3番目のページ付けリンクがある場合、3番目のリンクは不可解になり、アンカータグではありません。私は他のページで同じページ付けを使用しましたが、これは正常に機能していますが、これがこの問題を引き起こしています。

これがページ付けされたページの写真へのリンクです。ここでは、アクティブなページがまだ1であるのに、強調表示されたページは3であるため、3番目のページはクライニングできません。

これは画像へのリンクです

そして、これは私がこのページネーションでは達成できない他の実装ですが、これが私が望むものです:ここでは、現在のページが1番目で、ページごとに5つのアイテムがある合計13のアイテムがあります。

これは、目的の実装へのリンクです

4

1 に答える 1

0

total_rowsに問題があるという観点だけでなく、データベースから選択された行の数が得られます。where句を使用している場合は、count_allまたはcount_all_resultを使用する方がよいでしょう。

from
$config['total_rows'] = $this->db->get('comment_article')->num_rows();

to 
$config['total_rows'] = $this->db->get('comment_article')->count_all();

もう1つの変更は、プロジェクトを他のサーバーにデプロイするときに役立ちます

from
$config['base_url'] = 'http://localhost/ci/CodeIgniter_2.1.3/index.php/comment/article/'.$id;

to
$config['base_url'] = base_url('comment/article/'.$id); // it will automatically add default base_url

ほとんどのインポートで、$config['uri_segment']を追加する必要があります。デフォルトでページ番号が3であるセグメントを指定する必要があります。

$config['uri_segment'] = 3;

CIサイトのPaginationドキュメントをご覧ください

于 2013-01-07T05:06:13.567 に答える