我用Laravel 4.2,bootstrap和MySQL制作了一个proyect . 现在我有以下问题 .
我检索数据库记录,然后我使用分页显示它们 . 我以相同的方式为多个页面执行此操作,因此我创建了一个不重复自己的刀片模板 . 当我使用 Paginator
的 links
方法时出现问题 . 使用null参数时,该方法不会抛出任何异常,但它无法正常工作,因为无论您身在何处,链接始终都会将您重定向到主页面 .
在Laravel 4.2文档中,如下所述:
如果要指定用于分页的自定义视图,可以将视图传递给links方法:<?php echo $ users-> links('view.name'); ?>
但如果我尝试在我的刀片模板中执行类似的操作:
{{ $products->links('client.pages.search_results') }}
我得到以下异常:
Method Illuminate\View\View::__toString() must not throw an exception
EDIT
这是 search_results
模板:
@extends('client.layouts.client')
@section('content')
@include('client.includes.products', ['header_title' => "Results for $search",
'show_platform_icon' => true,
'view_name' => 'client.pages.search_results'])
@stop
这是 products
模板:
<div>
<div class="navbar navbar-default">
<div class="navbar-collapse navbar-header">
<h3>{{ $header_title }}</h3>
</div>
<div class="navbar-collapse navbar-right">
{{ Form::open(['class' => 'navbar-form']) }}
<div class="form-group">
<select class="form-control" id="sorter" >
<option disabled selected>Order by</option>
<option value="{{ URL::route('index') }}/name/asc">Name asc</option>
<option value="{{ URL::route('index') }}/name/desc">Name desc</option>
@if(Auth::check())
<option value="{{ URL::route('index') }}/discount/asc">Discount asc</option>
<option value="{{ URL::route('index') }}/discount/desc">Discount desc</option>
@else
<option value="{{ URL::route('index') }}/price/asc">Price asc</option>
<option value="{{ URL::route('index') }}/price/desc">Price desc</option>
@endif
</select>
</div>
{{ Form::close() }}
</div>
</div>
<div class="col-md-12">
<ul class="thumnails col-md-11">
@foreach ($products as $index => $product)
<li class="col-md-3 col-md-offset-1 thumbnail">
<a href="#product">
{{ HTML::image($product->game->thumbnail_image_path, $product->game->name) }}
</a>
<div class="caption">
@if($show_platform_icon)
<a href="#platform" class="pull-left">
{{ HTML::image($product->platform->icon_path, $product->platform->name) }}
</a>
@endif
<a href="#product">
<div class="text-center">
@if(Auth::check() && $product->discount)
<h3>
{{ floatval($product->price * ((100 - $product->discount) / 100)) }} €
<span class="label label-default">-{{ floatval($product->discount)}}%</span>
</h3>
@else
<h3>{{ floatval($product->price) }} €</h3>
@endif
</div>
</a>
</div>
</li>
@endforeach
</ul>
<div class="col-md-4 col-md-offset-4 text-center">
{{ $products->links($view_name) }}
</div>
</div>
</div>
1 回答
从下面的评论问题
我想你误解了
links('view')
是如何工作的 . 您传递的视图将用于显示分页链接 . 为了给你一个想法,这是默认的:slider-3.php渲染页面中的链接如何显示?应该是
?page=1
的东西几个小时之后...