douao1854 2014-02-18 03:08
浏览 60
已采纳

在codeigniter中自定义分页create_links()

<?php foreach(range('A', 'Z')as $key=>$letter)
      {
        echo anchor('KitchenGuruAdminController/Admin_recipe_browse/'.$letter, ' '.$letter);
      }
      echo "<BR><BR>";
 ?>

<table  cellpadding='5'>
<th>Delete</th>
<th></th>
<th>Id</th>
<th>Recipe name</th>
<th>Edit</th>

<?php if(isset($records)) : foreach($records as $recipe) : ?>   
        <tr>
        <td><input type="checkbox" name="idsToDelete[]" value="<?=$recipe['recipeid']?>" /><td>
        <td><?php echo $recipe['recipeid'] ?></td>
        <td><?php echo $recipe['recipename'] ?></td>
        <td><?php echo anchor('KitchenGuruAdminController/Admin_recipe_edit/'.$recipe['recipeid'], 'Click'); ?></td>
        </tr>
<?php endforeach; ?>
        <tr><?php echo $this->pagination->create_links(); ?></tr>
<?php else : ?>
<h5>Recipe Database Empty.</h5>
<?php endif; ?>
</table>
</br></br><input type="submit" name="delete_button" onclick="delete_alert()"value="Delete"/>
<?php form_close(); ?>

The above code is my view, nevermind the button and checkboxes, they are for deletion of rows.

I have successfully paginated my results. and created links from A-Z and send the corresponding letter as a segment.

Here is my controller for pagination browse:

function Admin_recipe_browse()
    {
        $character = $this->uri->segment(3);

        $config['base_url'] = base_url() . 'index.php/KitchenGuruAdminController/Admin_recipe_browse';
        $config['total_rows'] = $this->KitchenGuruAdminModel->browse_total_rows();
        $config['per_page'] = 5;
        $config['num_links'] = 10;
        $config['uri_segment'] = 3;

        $this->pagination->initialize($config);

        $data['records'] = $this->KitchenGuruAdminModel->get_records($character,$config['per_page'], $this->uri->segment(3));
        //$data['records'] = $this->KitchenGuruAdminModel->get_records($config['per_page'], $this->uri->segment(3));
        $data['links'] = $this->pagination->create_links();
        $this->load->view('Admin_recipe_browse', $data);
    }

The code works fine, if i click A. it will only show results with A as the first character. The problem is when i click on the pagination links. It replaces the uri segment of my letter to a number($config['per_page'];)

so when i go back to page 1 on my pagination links, it will not filter the results for the character link.

sample,

/segment1/segment2/A

this is my url after i click the links i made using foreach range.

my pagination is set to only show 5 per page, so when i click on page 2. the url becomes.

/segment1/segment2/5

Back to my question, i have thought of a solution, set my Character filter as segment(3) and the per_page as segment(4).

problem is i don't know how to customize $this->pagination->create_links();

Currently reading pagination class documentation on ellislab, although it doesnt tackle much on the create_links function. Is there any parameter i can pass to it to make it write on segment(4).

  • 写回答

1条回答 默认 最新

  • dongreng9864 2014-02-18 04:17
    关注

    Make the base url of pagination accomodate your character :

    $character = $this->uri->segment(3);
    $config['base_url'] = base_url(). 'index.php/KitchenGuruAdminController/Admin_recipe_browse/'.$character;
    

    And also change the

    $config['uri_segment'] = 4;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 Python如何后台操作Vmwake虚拟机键鼠
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容