码迷,mamicode.com
首页 > Web开发 > 详细

laraver ajax分页

时间:2015-08-04 10:50:36      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

1,设置分页容器参考laraver手册 我的设置代码如下:

//设置分页容器  /app/models/ZurbPresenter.php
<?php 
    class ZurbPresenter extends Illuminate\Pagination\Presenter {
    public function getPageLinkWrapper($url, $page, $rel = null)
    {
        $rel = is_null($rel) ? ‘‘ :  rel=".$rel.";
        return <li><a href=javascript:goodslist(".$url.");>.$page.</a></li>;
    }
    public function getDisabledTextWrapper($text)
    {
        return <li class="disabled"><span>.$text.</span></li>;
    }
    public function getActivePageWrapper($text)
    {
        return <li class="active"><span>.$text.</span></li>;
    }
}
//设置分页模板 /app/view/page/page.blade.php
<ul class="pagination">
    <?php echo with(new ZurbPresenter($paginator))->render(); ?>
</ul>
//设置配置文件 /app/config/view.php
<?php
return array(
    paths => array(__DIR__./../views),
    //‘pagination‘ => ‘pagination::slider-3‘,
    pagination => page.page,
);
2,控制器调用的方法:代码如下

private function toAjaxTpl($templateFile=‘‘,$data=‘‘) {
        $viewobj = View::make($templateFile,array(data=>$data));
        $path= $viewobj->getPath();
        ob_start();
        ob_implicit_flush(0);
        include($path);
        $content = ob_get_clean();
        return $content;
    }
public function getList(){
        $reult = $this->brand->paginate(2);
        $content = $this->toAjaxTpl(member::publish.ajaxtpl.ajaxsold,$reult);
        $data = [status=>true,data=>$content];
        return Response::json($data);
    }
3,ajax分页模板代码

<thead>
    <tr>
        <th>商品</th>
        <th>金额</th>
        <th>发布时间</th>
        <th>过期时间</th>
        <th>操作</th>
    </tr>
</thead>
<tbody>
<?php 
    foreach($data as $d){
?>
    <tr>
      <td valign="middle">
                <a href=""><img src="../images/uCenter/nail.jpg" width="80" height="80"/><?php echo $d->title ; ?></a>            </td>
      <td>9999元11</td>
      <td><?php echo $d->created_at; ?></td>
      <td><?php echo $d->validity_date; ?></td>
       <td><i class="icon icon-eye-open tip0"  data-toggle="tooltip" data-placement="top" title="查看"></i> | 
                   <i class="icon  icon-edit tip0" data-toggle="tooltip" data-placement="top" title="编辑"></i>           <br />                    <i class="icon  icon-chevron-down tip0" data-toggle="tooltip" data-placement="top" title="下架"></i> |                     <i class="icon icon-remove tip0"  data-toggle="tooltip" data-placement="top" title="删除"></i>
      </td>
    </tr>
<?php
    }
?>
</tbody>
<tfoot>
    <tr>
    <td cols=5 > <?php echo $data->links(); ?></td>
    </tr>
</tfoot>
................
//js代码:
<script type="text/javascript">
    var tm_classify=[];
    function expire(){
        var url = {{ route("member.publish.getlist") }};
         $.getJSON(url,function(data){
        console.info(data);
        $(#expire).html(data.data);
        }); 
    };
    function goodslist(url){
    $.getJSON(url,function(data){
        $(#expire).html(data.data);
    });
    }
</script>

laraver ajax分页

标签:

原文地址:http://www.cnblogs.com/qhorse/p/4701104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!