国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > access > 用symfony实现ajax分页效果

用symfony实现ajax分页效果

来源:程序员人生   发布时间:2014-09-06 11:40:39 阅读次数:4407次

用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】【注册】【打印】

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生