php - 将分页与查询字符串一起用于搜索表单,该表单的方法设置为在 codeigniter 中获取

标签 php codeigniter get pagination

我正在敲击键盘,试图找出一种使用带分页的查询字符串的方法,一切正常,直到 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 上偶然发现了一些答案/示例,这就是我写的:

Pagination配置文件有

$config['per_page'] = '1';
$config['uri_segment'] = '3';

和其他类似num_tag_open

Controller 类:

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

        }
    }
}

求救!小伙伴们帮帮我吧

最佳答案

我不敢相信,我花了几个小时在网上搜索解决方案! 它一直伴随着我。我应该在发布这个问题之前打开分页库并查看其内容。只需一行,问题就解决了。
我在索引方法中添加了以下行。
$config['first_url'] = '/index.php/search/index/?q='.$q;

关于php - 将分页与查询字符串一起用于搜索表单,该表单的方法设置为在 codeigniter 中获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6080093/

相关文章:

php - 来自数组的奇怪 str_replace 输出

javascript - 加载页面时多次获取请求

django - 将额外的上下文传递给 Django Haystack 模板

PHP读取每一行

php - 如何将点击的验证码的响应作为变量获取

php - WordPress 错误 : Sorry, 您无权访问此页面

php - 尝试将 Codeigniter Project 3.0 上传到主机时出现错误 404?

php - 如何使用 jQuery、AJAX 和 CodeIgniter 在 MYSQL 中输入时检查电子邮件是否存在

php - 如何在 codeigniter 中连接这些表

php - 如何在php中获取http请求来源