用symfony实现ajax分页效果
关键词: symfony 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();
- ?<
【作者: Liberal】【访问统计:】【2007年07月30日 星期一 10:11】【注册】【打印】
本文介绍了一个使用Symfony框架实现AJAX分页效果的方法。通过创建一个名为ajaxpager的类,可以轻松地为现有的网页添加AJAX分页功能。该类允许指定分页对象、更新后的div ID、请求完成时的视觉效果等。
1046

被折叠的 条评论
为什么被折叠?



