用symfony实现ajax分页效果

本文介绍了一个使用Symfony框架实现AJAX分页效果的方法。通过创建一个名为ajaxpager的类,可以轻松地为现有的网页添加AJAX分页功能。该类允许指定分页对象、更新后的div ID、请求完成时的视觉效果等。

用symfony实现ajax分页效果

关键词symfony ajax 分页

新建一个ajax分页的类:

  1. >?php
  2. /**
  3. @name ajaxpager.class.php
  4. @desc allows ajax pagination.
  5. $pager:pager object created using sfPropelPager
  6. $url:URL of desired action.(mostly current ajax action)
  7. $divId:id of div to be updated after pagination
  8. $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
  9. $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
  10. @author Ahmet ERTEK, erteka@gmail.com
  11. @copyright DVS Bilisim, www.dvs-tr.com
  12. @version 1.0.0
  13. */
  14. class ajaxpager
  15. {
  16. private $pager;
  17. private $divId;
  18. private $url;
  19. private $params;
  20. private $appear_effect;
  21. /**
  22. @name ajaxpager.class.php
  23. @desc allows ajax pagination.
  24. $pager:pager object created using sfPropelPager
  25. $url:URL of desired action.(mostly current ajax action)
  26. $divId:id of div to be updated after pagination
  27. $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
  28. $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
  29. @author Ahmet ERTEK, erteka@gmail.com
  30. @copyright DVS Bilisim, www.dvs-tr.com
  31. @version 1.0.0
  32. */
  33. public function ajaxpager($pager,$url,$divId,$params=null,$appear_effect='Appear')
  34. {
  35. $this-<pager=$pager;
  36. $this-<divId=$divId;
  37. $this-<url=$url;
  38. $this-<params=$params;
  39. $this-<appear_effect=$appear_effect;
  40. }
  41. /**
  42. @name ajaxpager.class.php
  43. @desc prints pagination.
  44. @author Ahmet ERTEK, erteka@gmail.com
  45. @copyright DVS Bilisim, www.dvs-tr.com
  46. @version 1.0.0
  47. */
  48. public function printPager()
  49. {
  50. $pager=$this-<pager;
  51. $url=$this-<url;
  52. $divId=$this-<divId;
  53. $appear_effect=$this-<appear_effect;
  54. if ($pager-<haveToPaginate())
  55. {
  56. echo link_to_remote('«', array(
  57. 'update' =< $divId,
  58. 'url' =< $url.'?page='.$pager-<getFirstPage(),
  59. 'complete'=<visual_effect($appear_effect, $divId),
  60. 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
  61. ), array('class'=<'contentLink'));
  62. link_to_remote('>', array(
  63. 'update' =< $divId,
  64. 'url' =< $url.'?page='.$pager-<getPreviousPage(),
  65. 'complete'=<visual_effect($appear_effect, $divId),
  66. 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
  67. ), array('class'=<'contentLink'));
  68. $links = $pager-<getLinks();
  69. foreach ($links as $page)
  70. {
  71. echo($page == $pager-<getPage()) ? $page : link_to_remote($page, array(
  72. 'update' =< $divId,
  73. 'url' =< $url.'?page='.$page,
  74. 'complete'=<visual_effect($appear_effect,$divId),
  75. 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
  76. ), array('class'=<'contentLink'));
  77. if ($page != $pager-<getCurrentMaxLink()){ echo "-"; }
  78. }
  79. echo link_to_remote('»', array(
  80. 'update' =< $divId,
  81. 'url' =< $url.'?page='.$pager-<getNextPage(),
  82. 'complete'=<visual_effect($appear_effect, $divId),
  83. 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
  84. ), array('class'=<'contentLink'));
  85. link_to_remote('<', array(
  86. 'update' =< $divId,
  87. 'url' =< $url.'?page='.$pager-<getLastPage(),
  88. 'complete'=<visual_effect($appear_effect, $divId),
  89. 'loading'=<"$('$divId').innerHTML='>img src=/images/indicator.gif border=0<'",
  90. ), array('class'=<'contentLink'));
  91. }
  92. }
  93. }
  94. ?<

调用方法:

  1. >?php
  2. $ajax_pager=new ajaxpager($pager,'myDivId','account/pictures?id='.$accountId,null,'SlideDown');
  3. $ajax_pager-<printPager();
  4. ?<

【作者: Liberal】【访问统计:】【2007年07月30日 星期一 10:11】【注册】【打印】

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值