Codeigniter分页链接转到404页面未找到 [英] Codeigniter pagination link go to 404 Page Not Found

查看:137
本文介绍了Codeigniter分页链接转到404页面未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个分页与搜寻结果< a>实现到我的CI项目,但我无法让我的分页链接转到下一页,例如:



我的搜索页,当它第一次加载是<当我点击分页链接将转到 http:// localhost / ci_project / search / 2 http:// localhost / ci_project / search / code>,该页面显示为 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;
}
}

Controller: p>

  function search()
{
$ keywords = $ this-> input-&搜索');

$ 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'] ='搜索';

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

感谢。

解决方案

尝试:

  $ config ['base_url'] = base_url搜索'); 
$ config ['uri_segment'] = 3;


I had this Paginate with search result implemented into my CI project, However I was unable to have my paginate links go to the next page, for example:

my search page when it first loaded is http://localhost/ci_project/search, when I clicked the paging link which will go to http://localhost/ci_project/search/2, the page is shown 404 Page Not Found.

Can someone please help me to figure out what's wrong in my code? I tried a lot of suggestion on the solution but can't help, most of the issue is came from $config['base_url'] = base_url('search');, but none of them are help.

Model:

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;
    }
}

Controller:

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);
}

Thanks.

解决方案

Try:

$config['base_url'] = base_url('controller_name/search');
$config['uri_segment'] = 3;

这篇关于Codeigniter分页链接转到404页面未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆