[英]Codeigniter pagination link go to 404 Page Not Found
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:我在 CI 项目中实现了带有搜索结果的分页,但是我无法将分页链接转到下一页,例如:
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
.我第一次加载时的搜索页面是
http://localhost/ci_project/search
,当我单击将转到http://localhost/ci_project/search/2
的分页链接时,该页面显示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');
我尝试了很多关于解决方案的建议,但无济于事,大部分问题来自
$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;
http://localhost/ci_project/search/2
in codeigniter is probably trying to execute a method called 2
with the usual configuration, if your method is search
be sure to call the url at http://localhost/ci_project/search_controller/search/2
. codeigniter 中的
http://localhost/ci_project/search/2
可能正在尝试使用通常的配置执行名为2
的方法,如果您的方法是search
,请务必调用http://localhost/ci_project/search_controller/search/2
处的 url http://localhost/ci_project/search_controller/search/2
。
If you want to change the configuration for some reason, you can start digginhere如果你因为某种原因想改变配置,你可以从这里开始diggin
Try this试试这个
$config['base_url'] = base_url('index.php/controller_name/method_name');
No need change routes config, this works for me.无需更改路由配置,这对我有用。
试试这个:如果你在索引页面调用索引方法这样..
'base_url' => base_url('page/index'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.