使用带有查询字符串的分页作为搜索表单,该表单的方法设置为获取 codeigniter
我正在敲击键盘,试图找出一种将查询字符串与分页一起使用的方法,一切正常,直到出现 FIRST
页面链接。
所有其他链接都将查询字符串附加到其末尾,但First
页面链接错过了查询字符串
其他页面的链接:
http://localhost/index.php/search/index/9?q=some_Data_From_Form
第一页链接显示了我已经添加的链接在 $config['base_url']
中设置 变量:
http://localhost/index.php/search/index/
搜索表单:
$attributes=array('id'=>'search','class'=>'clearfix','method'=>'get');
echo form_open(base_url().'index.php/search/index',$attributes);
它有一个名称设置为 q
的文本框。
我在 stackoverflow 上偶然发现了一些答案/示例,这就是我写的:
分页配置文件
$config['per_page'] = '1';
$config['uri_segment'] = '3';
以及其他类似 num_tag_open 等的
控制器类:
class Search extends CI_Controller {
public function Search(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('input');
$this->load->model('blog_model');
$this->load->library('pagination');
$this->config->load('pagination'); //other pagination related config variables
}
public function index($page=0){
$q = trim($this->input->get('q'));
if(strlen($q)>0){
//validate input and show data
$config['enable_query_strings']=TRUE;
$getData = array('q'=>$q);
$config['base_url'] = 'http://localhost/index.php/search/index/';
$config['suffix'] = '?'.http_build_query($getData,'',"&");
$data['rows'] = $this->blog_model->getBySearch($q,$this->config->item('per_page'),$page);
if(empty($data['rows'])){
//no results found
}else{
//match found
$config['total_rows'] = $this->blog_model->getBySearchCount($q);
$this->pagination->initialize($config);
$link->linkBar = $this->pagination->create_links();
$this->load->view('myview',array($data,$link));
}
}else if(strlen($q)==0){
//warn user for the missing query and show a searchbox
}
}
}
SOS!伙计们,请帮帮我
I'm banging my head on the keyboard trying to figure out a way to use query string with pagination every thing works fine until FIRST
page link appears.
All other links have the query string appended to their end but the First
page link misses the query string
Links for other pages:
http://localhost/index.php/search/index/9?q=some_Data_From_Form
The FIRST page link show the link that I've set in the $config['base_url']
variable:
http://localhost/index.php/search/index/
The search form:
$attributes=array('id'=>'search','class'=>'clearfix','method'=>'get');
echo form_open(base_url().'index.php/search/index',$attributes);
It has a textbox with the name set to q
.
I stumbled upon a few answers/examples on stackoverflow and this is what I wrote:
The Pagination configuration file has
$config['per_page'] = '1';
$config['uri_segment'] = '3';
and others like num_tag_open
etc.
The controller class:
class Search extends CI_Controller {
public function Search(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('input');
$this->load->model('blog_model');
$this->load->library('pagination');
$this->config->load('pagination'); //other pagination related config variables
}
public function index($page=0){
$q = trim($this->input->get('q'));
if(strlen($q)>0){
//validate input and show data
$config['enable_query_strings']=TRUE;
$getData = array('q'=>$q);
$config['base_url'] = 'http://localhost/index.php/search/index/';
$config['suffix'] = '?'.http_build_query($getData,'',"&");
$data['rows'] = $this->blog_model->getBySearch($q,$this->config->item('per_page'),$page);
if(empty($data['rows'])){
//no results found
}else{
//match found
$config['total_rows'] = $this->blog_model->getBySearchCount($q);
$this->pagination->initialize($config);
$link->linkBar = $this->pagination->create_links();
$this->load->view('myview',array($data,$link));
}
}else if(strlen($q)==0){
//warn user for the missing query and show a searchbox
}
}
}
S.O.S! Guys, please help me out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我简直不敢相信,我花了几个小时在网上搜索解决方案!
它一直伴随着我。在发布这个问题之前,我应该打开分页库并查看其内容。只需一行,问题就解决了。
我在索引方法中添加了以下行。
$config['first_url'] = '/index.php/search/index/?q='.$q;
I can't believe this, I spent hours searching the web for a solution !
It was always with me.I should have opened the pagination library and viewed its content before I posted this question.Just one line and problem solved.
I added the following line in the index method.
$config['first_url'] = '/index.php/search/index/?q='.$q;