3

このPaginate と検索結果を CI プロジェクトに実装しましたが、次のように Paginate リンクを次のページに移動させることができませんでした。

最初に読み込まれたときの検索ページはhttp://localhost/ci_project/searchで、 に移動するページング リンクをクリックするとhttp://localhost/ci_project/search/2、そのページが表示され404 Page Not Foundます。

誰かが私のコードの何が問題なのかを理解するのを手伝ってくれますか? 私は解決策について多くの提案を試みましたが、解決できません。ほとんどの問題は から来て$config['base_url'] = base_url('search');いますが、どれも助けにはなりません。

モデル:

public function do_search_count($keywords)
{
    $sql = "SELECT COUNT(*) AS cnt FROM products WHERE MATCH (name, manufacturer) AGAINST ('".$keywords."')";
    $q = $this->db->query($sql);
    $row = $q->row();
    return $row->cnt;
}

public function do_search($keywords, $per_page, $limit)
{
    $this->db->escape($keywords);

    $this->db->where('MATCH (name, manufacturer) AGAINST ("'.$keywords.'") LIMIT '.$per_page.', '.$limit, NULL, FALSE);
    $query = $this->db->get('products');

    if($query->num_rows() > 0){
        return $query->result();
    }else{
        return false;
    }
}

コントローラ:

function search()
{
    $keywords = $this->input->post('search');

    $searchterm = $this->db_model->searchterm_handler($this->input->get_post('search', TRUE));
    $limit = ($this->uri->segment(2) > 0)?$this->uri->segment(2):0;

    $config['base_url'] = base_url('search');
    $config['total_rows'] = $this->db_model->do_search_count($searchterm);
    $config['per_page'] = 5;
    $config['uri_segment'] = 2;
    $config['use_page_numbers'] = TRUE;
    $choice = $config['total_rows'] / $config['per_page'];
    $config['num_links'] = round($choice);  

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

    $data['results'] = $this->db_model->do_search(trim($keywords), $limit, $config['per_page']);
    $data['pagination'] = $this->pagination->create_links();
    $data['searchterm'] = $searchterm;

    $data['total'] = count($data['results']);
    $data['title'] = 'Search';

    $this->load->view('header', $data);
    $this->load->view('search', $data);
    $this->load->view('footer', $data);
}

ありがとう。

4

4 に答える 4

3

試す:

$config['base_url'] = base_url('controller_name/search');
$config['uri_segment'] = 3;
于 2013-10-01T12:43:47.747 に答える
0

http://localhost/ci_project/search/2in codeigniter はおそらく2、通常の構成で呼び出されたメソッドを実行しようとしています。メソッドがsearch必ず で URL を呼び出す場合http://localhost/ci_project/search_controller/search/2

何らかの理由で構成を変更したい場合は、ここからdigginを開始できます

于 2013-10-01T13:33:47.513 に答える