Creating Pagination With CakePHP For Custom Template Links

故事扮演 提交于 2019-12-07 19:41:45

问题


I've following custom template for pagination links

<li class="prev"><a href="#">prev</a></li>
<li><a href="#" class="active">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">6</a></li>
<li><a href="#">7</a></li>
<li><a href="#">8</a></li>
<li>...</li>
<li><a href="#">30</a></li>
<li class="next"><a href="#">next</a></li>

I've tried it by using following code(cakephp 2.3 version) but not getting the result as required.

<?php
     echo $this->Paginator->prev('<', array( 'class' => '', 'tag' => 'li' ), null, array('class' => 'prev', 'tag' => 'li'));  
     echo $this->Paginator->numbers(array('tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'currentTag' => 'a' ));  
     echo $this->Paginator->next('>', array('class' => 'next', 'tag' => 'li' ), null, array( 'class' => 'next', 'tag' => 'li'));  
?>

Please help me out to get it done.. Thanks in advance.


回答1:


This is just a sample of my custom template for pagination links, that I made for use with bootstrap. You can modify it accordingly to your needs

<ul>
<?php
    echo $this->Paginator->first('&lsaquo;', array('tag' => 'li', 'title' => __('First page'), 'escape' => false));
    echo $this->Paginator->prev('&laquo;', array('tag' => 'li',  'title' => __('Previous page'), 'disabledTag' => 'span', 'escape' => false), null, array('tag' => 'li', 'disabledTag' => 'span', 'escape' => false, 'class' => 'disabled'));
    echo $this->Paginator->numbers(array('separator' => false, 'tag' => 'li', 'currentTag' => 'span', 'currentClass' => 'active'));
    echo $this->Paginator->next('&raquo;', array('tag' => 'li', 'disabledTag' => 'span', 'title' => __('Next page'), 'escape' => false), null, array('tag' => 'li', 'disabledTag' => 'span', 'escape' => false, 'class' => 'disabled'));
    echo $this->Paginator->last('&rsaquo;', array('tag' => 'li', 'title' => __('First page'), 'escape' => false));
?>
</ul>

The ellipsis ... is created automatically by Paginator::numbers() according to the CakeBook, but you can change it to whatever you want.

I hope it works out for you



来源:https://stackoverflow.com/questions/18181340/creating-pagination-with-cakephp-for-custom-template-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!