使用带有查询字符串的分页作为搜索表单,该表单的方法设置为获取 codeigniter

发布于 2024-11-08 15:47:28 字数 2365 浏览 0 评论 0原文

我正在敲击键盘,试图找出一种将查询字符串与分页一起使用的方法,一切正常,直到出现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2024-11-15 15:47:28

我简直不敢相信,我花了几个小时在网上搜索解决方案!
它一直伴随着我。在发布这个问题之前,我应该打开分页库并查看其内容。只需一行,问题就解决了。
我在索引方法中添加了以下行。
$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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文