memo:zendでpaginatorを手抜きでajax化する
手抜きなのでコントローラーをいじるのは御法度です。
phtmlのみでやります。働きたくないです。
方法
1.jqueryを用意する
sshでjqueryを置きにいったりすると手抜きではないです。バージョンの心配とか発生しますから。
googleからとってきたらいいでしょう。
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript">google.load("jquery","1.3");</script>
2.paginatorをdivで囲むid="paginator"とか
普通は既にかこんでありますでしょ?classでもいいですよ。元からpaginatorがはき出すclassでもいいですしね。
<div id="pagination"> <!-- pagination --> <?php echo $this->paginationControl($this->paginator,'Sliding','my_pagination_control.phtml'); ?> <!-- /pagination --> </div>
3.paginationはリンクなのでjqueryでイベントを設置
今回の書き換え対象はid=contentsに入っています
<script> $(function(){ $("#pagination").find("a").click(function(){ var _uri = $(this).attr("href"); $("#content").html("<img src='http://www.google.co.jp/intl/ja_jp/images/logo.gif' style='position:relative;top:30%;left:30%;' />"); //適当なローディングを $.ajax({ type:"GET", url: _uri, dataType:"text/html", async: true, success:function(data){ // alert(data); //ごめんなさい $("#content") .fadeOut('normal',function(){ $("#content").html($(data).find("#content")) .fadeIn('normal'); }); } }); return false; }); }); </script>
結果:alertをみて、やっぱりごめんなさい。といった感じ。
無駄なデータ転送が発生しますが、ajax導入前と同じ転送量なので気にしたら負けですね。