Cha*_*lla 10 php pagination codeigniter get
我正在敲打键盘试图找出一种方法来使用查询字符串和分页,每一件事都可以正常工作,直到FIRST出现页面链接.
所有其他链接都将查询字符串附加到其末尾但First页面链接misses the query string
其他页面的链接:
http://localhost/index.php/search/index/9?q=some_Data_From_Form
Run Code Online (Sandbox Code Playgroud)
FIRST页面链接显示我在$config['base_url']
变量中设置的链接:
http://localhost/index.php/search/index/
Run Code Online (Sandbox Code Playgroud)
搜索表单:
$attributes=array('id'=>'search','class'=>'clearfix','method'=>'get');
echo form_open(base_url().'index.php/search/index',$attributes);
Run Code Online (Sandbox Code Playgroud)
它有一个名称设置为的文本框q.
我在stackoverflow上偶然发现了几个答案/示例,这就是我写的:
分页配置文件有
$config['per_page'] = '1';
$config['uri_segment'] = '3';
Run Code Online (Sandbox Code Playgroud)
和其他类似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
}
}
}
Run Code Online (Sandbox Code Playgroud)
SOS!伙计们,请帮帮我
Cha*_*lla 11
我无法相信这一点,我花了几个小时在网上寻找解决方案!它始终与我同在.我应该在发布这个问题之前打开分页库并查看其内容.只需一行,问题就解决了.
我在索引方法中添加了以下行.
$config['first_url'] = '/index.php/search/index/?q='.$q;
| 归档时间: |
|
| 查看次数: |
4094 次 |
| 最近记录: |