用symfony实现ajax分页效果
来源:程序员人生 发布时间:2014-09-06 11:40:39 阅读次数:4407次
用symfony实现ajax分页效果
关键词: symfony ajax 分页
新建一个ajax分页的类:
- >?php
- /**
- @name ajaxpager.class.php
- @desc allows ajax pagination.
- $pager:pager object created using sfPropelPager
- $url:URL of desired action.(mostly current ajax action)
- $divId:id of div to be updated after pagination
- $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
- $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
- @author Ahmet ERTEK, erteka@gmail.com
- @copyright DVS Bilisim, www.dvs-tr.com
- @version 1.0.0
-
- */
- class ajaxpager
- {
- private $pager;
- private $divId;
- private $url;
- private $params;
- private $appear_effect;
-
- /**
- @name ajaxpager.class.php
- @desc allows ajax pagination.
- $pager:pager object created using sfPropelPager
- $url:URL of desired action.(mostly current ajax action)
- $divId:id of div to be updated after pagination
- $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
- $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
- @author Ahmet ERTEK, erteka@gmail.com
- @copyright DVS Bilisim, www.dvs-tr.com
- @version 1.0.0
-
- */
- public function ajaxpager($pager,$url,$divId,$params=null,$appear_effect='Appear')
- {
- $this-<pager=$pager;
- $this-<divId=$divId;
- $this-<url=$url;
- $this-<params=$params;
- $this-<appear_effect=$appear_effect;
-
- }
- /**
- @name ajaxpager.class.php
- @desc prints pagination.
- @author Ahmet ERTEK, erteka@gmail.com
- @copyright DVS Bilisim, www.dvs-tr.com
- @version 1.0.0
-
- */
- public function printPager()
- {
- $pager=$this-<pager;
- $url=$this-<url;
- $divId=$this-<divId;
- $appear_effect=$this-<appear_effect;
-
- if ($pager-<haveToPaginate())
- {
- echo link_to_remote('?', array(
- 'update' =< $divId,
- 'url' =< $url.'?page='.$pager-<getFirstPage(),
- 'complete'=<visual_effect($appear_effect, $divId),
- 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
- ), array('class'=<'contentLink'));
-
- link_to_remote('>', array(
- 'update' =< $divId,
- 'url' =< $url.'?page='.$pager-<getPreviousPage(),
- 'complete'=<visual_effect($appear_effect, $divId),
- 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
- ), array('class'=<'contentLink'));
-
- $links = $pager-<getLinks();
- foreach ($links as $page)
- {
- echo($page == $pager-<getPage()) ? $page : link_to_remote($page, array(
- 'update' =< $divId,
- 'url' =< $url.'?page='.$page,
- 'complete'=<visual_effect($appear_effect,$divId),
- 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
- ), array('class'=<'contentLink'));
-
- if ($page != $pager-<getCurrentMaxLink()){ echo "-"; }
- }
-
- echo link_to_remote('?', array(
- 'update' =< $divId,
- 'url' =< $url.'?page='.$pager-<getNextPage(),
- 'complete'=<visual_effect($appear_effect, $divId),
- 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
- ), array('class'=<'contentLink'));
-
- link_to_remote('<', array(
- 'update' =< $divId,
- 'url' =< $url.'?page='.$pager-<getLastPage(),
- 'complete'=<visual_effect($appear_effect, $divId),
- 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
- ), array('class'=<'contentLink'));
- }
- }
- }
-
- ?<
调用方法:
- >?php
- $ajax_pager=new ajaxpager($pager,'myDivId','account/pictures?id='.$accountId,null,'SlideDown');
- $ajax_pager-<printPager();
- ?<
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
------分隔线----------------------------
------分隔线----------------------------