分页器->;links()导致方法IlluminateViewView::__toString()不能引发异


paginator->links() results in Method IlluminateViewView::__toString() must not throw an exception

我正在用Laravel 4.2、bootstrap和MySQL做一个项目。现在我有以下问题。

我检索数据库记录,然后使用分页显示它们。我用同样的方式写了好几页,所以我创建了一个刀片模板来避免重复。当我使用Paginatorlinks方法时,问题就出现了。使用null参数时,该方法不会引发任何异常,但它无法正常工作,因为无论您身在何处,链接都会将您重定向到主页。

在Laravel 4.2文档中,如下所述:

如果要指定用于分页的自定义视图可以将视图传递给链接方法:

<?php echo $users->links('view.name'); ?>

但如果我试图在我的刀片模板中做这样的事情:

{{ $products->links('client.pages.search_results') }}

我得到以下异常:

方法Illuminate''View''View::__toString()不能引发异常

编辑

这是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>

从问题下方的评论

我想你误解了links('view')的工作原理。您传递的视图将用于显示分页链接。为了给你一个想法,这是默认的:slider-3.php

好的,我看到我的错误了。现在我必须弄清楚为什么当我使用links()时,它会将我重定向到主页,而不是停留在实际页面中。非常感谢。

渲染页面中的链接看起来如何?应该是?page=1

几个小时后

我解决了这个问题。我把我的一条路线的分页过程搞砸了。分页器试图访问页面段,但路由正在将该请求重定向到主页。没有你的帮助我做不到。

相关文章:
  • 没有找到相关文章