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
2,控制器调用的方法:代码如下
public function toAjaxTpl($templateFile='',$data='') {
// 模板文件不存在直接返回
//if(!is_file($templateFile)) return NULL;
// dd(View::make($templateFile,$data));
$viewobj = View::make($templateFile,array('data'=>$data));
$path= $viewobj->getPath();
// 页面缓存
ob_start();
ob_implicit_flush(0);
// 模板阵列变量分解成为独立变量
// extract($data, EXTR_OVERWRITE);
// 直接载入PHP模板
// dd(View::make($templateFile,$data));
include($path);
//include('member::publish.partials.publish_sale_left');
//include $templateFile;
//获取并清空缓存
$content = ob_get_clean();
// 输出模板文件
return $content;
}
public function ajaxPageList(){
$type = Request::get('type');
$goodscate = Request::get('goodscate');
$modobj = $this->aboutGoods($goodscate);
if($type=='expire'){
$reult = $modobj->where('status',0)->paginate(2);
}else if($type=='unpublish'){
$reult = $modobj->where('status',0)->paginate(2);
}
$reult->goodscate = $goodscate;
$content = $this->toAjaxTpl('member::publish.ajaxtpl.ajaxsold',$reult);
$data = ['status'=>true,'data'=>$content,'type'=>$type];
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 id="data_<?php echo $d->id; ?>" >
<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> |
<a href="<?php echo route('member.publish.saler.edit',[$d->id,$data->goodscate]); ?>" class="icon icon-edit tip0" data-toggle="tooltip" data-placement="top" title="编辑"></a>
<br />
<i class="icon icon-chevron-up tip0" onclick="upGoods(<?php echo $d->id; ?>);" data-toggle="tooltip" data-placement="top" title="上架"></i> |
<i class="icon icon-remove tip0" onclick="deleteGoods(<?php echo $d->id; ?>);" data-toggle="tooltip" data-placement="top" title="删除"></i>
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<td cols='5' > <?php echo $data->links('page.page'); ?></td>
</tr>
</tfoot>
................
//js代码:
$(function(){
var url = '{{ route("member.publish.saler.ajaxpagelist") }}';
$.getJSON(url,{type:'unpublish',goodscate:'{{ $datas->goodscate }}'},function(data){
$('#unpublish').html(data.data);
});
});
$('.unpublish').click(function(){
var url = '{{ route("member.publish.saler.ajaxpagelist") }}';
$.getJSON(url,{type:'unpublish', goodscate:'{{ $datas->goodscate }}'},function(data){
$('#unpublish').html(data.data);
});
});
$('.expire').click(function(){
var url = '{{ route("member.publish.saler.ajaxpagelist") }}';
$.getJSON(url,{type:'expire', goodscate:'{{ $datas->goodscate }}'},function(data){
//console.info(data);
$('#expire').html(data.data);
});
});
function deleteGoods(id){
if (confirm("确认要删除?")){
var url = '{{ route("member.publish.saler.deletegoods") }}';
$.getJSON(url,{id:id,downgoods:'{{ $datas->goodscate }}' },function(data){
$('#data_'+id).remove();
});
}
}
function upGoods(id){
if(confirm("你要上架架该商品?")){
var url = '{{ route("member.publish.saler.upanddown") }}';
$.getJSON(url,{id:id,upanddown:1,goods:'{{ $datas->goodscate }}'},function(data){
$('#data_'+id).remove();
});
}
}
function goodslist(url){
var index = $('.subTabHead').children(".active").index();
if (index == 0){
var type = "unpublish";
}else{
var type = "expire" ;
};
$.getJSON(url,{type:type, goodscate:'{{ $datas->goodscate }}'},function(data){
//console.info(data);
$("#"+type).html(data.data);
})
}