laraver ajax分页

时间:2021-09-03 16:16:57
,设置分页容器参考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',
);
,控制器调用的方法:代码如下 private function toAjaxTpl($templateFile='',$data='') {
        $viewobj = View::make($templateFile,array('data'=>$data));
        $path= $viewobj->getPath();
        ob_start();
        ob_implicit_flush();
        include($path);
        $content = ob_get_clean();
        return $content;
    }
public function getList(){
        $reult = $this->brand->paginate();
        $content = $this->toAjaxTpl('member::publish.ajaxtpl.ajaxsold',$reult);
        $data = ['status'=>true,'data'=>$content];
        return Response::json($data);
    }
,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="" height=""/><?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='' > <?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>