php使用form方式分页,php – 对搜索表单使用查询字符串分页,该表单的方法设置为codeigniter...

我正在敲打键盘试图找出一种方法来使用查询字符串和分页,每一件事情都可以正常工作,直到FIRST页面链接出现.

所有其他链接都将查询字符串附加到其末尾,但是第一页链接错过了查询字符串

其他页面的链接:

http://localhost/index.php/search/index/9?q=some_Data_From_Form

FIRST页面链接显示我在$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

}

}

}

S.O.S!伙计们,请帮帮我

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值