duanlu9816 2014-10-17 07:20
浏览 36
已采纳

CodeIgniter:分页不允许我通过发布表单来更改功能

So I have a page that lists sales leads, this page has a filter form that users submit to filter the list so that it only displays data they choose (as filter criteria), it also has pagination, whenever I use the pagination (as in click on one of the links) and then use the filter, the filter doesn't work, I feel like the problem resides either in the base_url config of the pagination or the uri_segment, as when I post the filter data it is supposed to call a function (filter) which obviously changes the last uri segment from 'list' to 'filter', which happens fine when I don't use pagination, but when I use it and then use the filter it just appends 'filter' to the end, so I end up with 'lists/filter' which isn't right, how can I solve this? :s I've tried removing/changing the uri_segment, is there anyway I can modify the base_url variable of the pagination config to allow it to work? Also when I click on any link that isn't the first page, the number of results displays in my uri, will this affect anything?

Relevant code: Controller:

public function lists($offset = 0) { 
        $this->load->library('pagination');
        $limit = 13;
        $this->load->model('listsalemod'); //load the model that contains the database functionality.
        $lead = $this->listsalemod->listlead($limit, $offset); //load the function that lists leads and pass it to a variable
        $cli = $this->listsalemod->listcli(); //load the function that lists clents and pass it to a variable
        $data = array(); //create an array
        $data['lead'] = $lead['records']; //pass lead data to array
        $data['cli'] = $cli; //pass client data to array 
        $config['base_url'] = site_url('list_sales/lists');
        $config['total_rows'] = $lead['count'];
        $config['per_page'] = 13;
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $this->load->library('pagination');
        $data['pagination'] = $this->pagination->create_links();
        $this->load->view('list_sales', $data); //load the view and pass in the data.

View:

<body>   
        <div id="container">
        <form method="post" action="filter">
            BFstaff <input type=text name="staff">
            date:   <input type=text name="date">
            Client  <input type=text name="client">
            <input type="submit" value="submit">
        </form>
        <table id="table">
         <tr>
         <th>short description</th>
         <th>Client</th>
         <th>Created</th>
         <th>view</th>
        <div id="pagination">
        <?php
        echo $pagination;
        ?>

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • duankaolei2921 2014-10-17 07:55
    关注

    So I figured it out, basically I am posting my form to 'filter' when I should be posting it to '/my_controller/filter' so that it doesn't just append the method to the url that pagination creates, it now rewrites it from the controller segment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?