codeIgniter分页-不会转到搜索结果的下一个链接 [英] codeIgniter pagination- doesn't go to the next link of searched results

查看:82
本文介绍了codeIgniter分页-不会转到搜索结果的下一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用分页搜索结果.搜索工作正常.搜索后显示前10条记录.但是,当我单击下一步按钮时,所有内容都消失了,并显示了一个空白页面.

I am using pagination for searched results. Searching is working perfectly. The first 10 records are shown after the search. But when I click the next button everything disappears and an empty page is displayed.

任何想法在我的代码中可能出错的地方,将不胜感激.

Any ideas what might be wrong in my code would be appreciated.

模型

function search_bookings($time, $title, $payment, $start_date, $end_date,$limit, $start, $type) {

        $this->db->select('reservations.*');
        $this->db->from('reservations');
        $this->db->where('is_deleted', '0');
        $this->db->order_by('date_cal',"desc");

         if (!empty($time) && !is_null($time)) {
            $this->db->where('reservations.type', $time);
        }
        if (!empty($payment) && !is_null($payment)) {
            $this->db->where('reservations.advanced_payment_status', $payment);
        }

        if (!empty($title) && !is_null($title)) {
            $this->db->where('reservations.title', $title);
        }

        if (!empty($start_date) && !is_null($start_date)) {
            $this->db->where('reservations.date_cal >=', $start_date);
            $this->db->where('reservations.date_cal <=', $end_date);
        }

         if ($type == 'half') {
            $this->db->limit($limit, $start);
        }
        $query = $this->db->get();
        return $query->result();
    }

控制器

 function search_reservations($start = 0) {
        $reservation_service = new Reservation_service();
        $config = array();

        $config["base_url"] = site_url() . "/dashboard/manage_bookings/";
        $config["per_page"] = 10;
        $config["uri_segment"] = 4;
        $config["num_links"] = 4;

        $time = $this->input->post('type', TRUE);
        $title = $this->input->post('title', TRUE);
        $payment = $this->input->post('payment', TRUE);
        $date_from = $this->input->post('date_from', TRUE);
        $date_to = $this->input->post('date_to', TRUE);
        $searched_results = $reservation_service->search_bookings($time, $title, $payment, $date_from, $date_to, $config["per_page"], $start, 'half');
        $data['search_results'] = $searched_results;
        $config["total_rows"] = count($reservation_service->search_bookings($time, $title, $payment, $date_from, $date_to, $config["per_page"], 0, 'all'));
        $this->pagination->initialize($config);

        $data["links"] = $this->pagination->create_links();

        $this->load->view('body_pages/search_results', $data);
    }

搜索结果视图

<table  class="display table table-bordered table-striped" id="bookings_table">
    <thead>
        <tr>
            <th>#</th>
            <th>Date</th>
            <th>Hall</th>
            <th>Time</th>                               
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 0;
        foreach ($search_results as $result) {
            ?>
            <tr id="bookings_<?php echo $result->id; ?>">
                <td><?php echo ++$i; ?></td>
                <td><?php echo $result->date_cal; ?></td>
                <td><?php if ("RP" == $result->title) { ?><?php
                        echo "Royal Princess Ballroom (Downstairs)";
                    }
                    ?>
                    <?php if ("GK" == $result->title) { ?><?php
                        echo "Grand Kings Ballroom (Upstairs)";
                    }
                    ?>
                </td>
                <td><?php echo $result->type; ?></td>  
                <td align="center">    
                    <a class="btn btn-primary btn-xs" onclick="display_edit_reservation_pop_up(<?php echo $result->id; ?>)"><i class="fa fa-pencil"  title="Update"></i></a>
                    <a class="btn btn-danger btn-xs" onclick="delete_bookings(<?php echo $result->id; ?>)" ><i class="fa fa-trash-o " title="Remove"></i></a>
                </td>
            </tr>
        <?php } ?>

    </tbody>

</table>

<div class="pagination">
    <?php echo $links; ?>
</div>                                          

推荐答案

您将从POST中获取$ time,$ title,$ payment,$ date_from,$ date_to变量.

You are taking the $time, $title, $payment, $date_from, $date_to variables from POST.

分页链接类似于-home/search_reservations/2

The paginiation links are like - home/search_reservations/2

一旦用户单击这些链接,帖子中的搜索数据就会丢失.如果希望它们影响所有页面,则需要将搜索参数保留在记录中.

once user clicks on those links the search data from post is lost. you need to keep your search parameters on the record if you want them to affect all the pages.

做到这一点的2种方法-

2 ways to do that-

1)使用GET而不是POST.将搜索参数保留在生成的分页链接的查询字符串中.这样,所有页面都将具有搜索参数.如果您要共享/添加搜索结果的特定页面,则也很有用.例如,您的页面将被链接为-

1) use GET instead of POST. keep your search parameters in the query string of your generated pagination links. This way all the pages will have the search parameters. Also useful if you want to share/bookmark a specific page of the search result. E.g your pages will be linked like -

www.yoursite.com/home/search_reservations/2?time=123&title=123&payment=123&date_from=123&date_to=123 

2)将搜索参数保留在会话中.代码中的代码混乱得多,但URL的代码更漂亮.

2) keep the search parameter in session. A lot messier in the code but prettier in the URL.

这篇关于codeIgniter分页-不会转到搜索结果的下一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆