【问题标题】:Append to pagination links URL in Laravel附加到 Laravel 中的分页链接 URL
【发布时间】:2015-01-12 21:01:35
【问题描述】:

如何追加:

#products

到 Laravel 分页链接方法使用的分页 URL 的末尾,以便我可以在地址栏中得到以下内容?:

products?page=3#products

这样我的移动用户和使用低分辨率桌面的人每次使用分页链接导航时都不必向下滚动页面。


这是我的配置/视图中的内容:

/*
    |--------------------------------------------------------------------------
    | Pagination View
    |--------------------------------------------------------------------------
    |
    | This view will be used to render the pagination link output, and can
    | be easily customized here to show any view you like. A clean view
    | compatible with Twitter's Bootstrap is given to you by default.
    |
    */

    'pagination' => 'products.ProductPresenter',

我得到:

Method Illuminate\View\View::__toString() must not throw an exception

根据 Laravel 文档,我的演示者:

class ProductPresenter extends Illuminate\Pagination\Presenter {

    public function getActivePageWrapper($text)
    {
        return '<li class="current"><a href="">'.$text.'</a></li>';
    }

    public function getDisabledTextWrapper($text)
    {
        return '<li class="unavailable"><a href="">'.$text.'</a></li>';
    }

    public function getPageLinkWrapper($url, $page, $rel = null)
    {
        return '<li><a href="'.$url.'">'.$page.'</a></li>';
    }

}

【问题讨论】:

  • 通过创建自己的 Custom Presenter 来更改 Laravel 生成的分页。
  • @Bogdan 我跟着那个,但我得到'没有为 [ProductPresenter] 定义提示路径':(
  • 请发布您正在使用的代码。
  • @Bogdan 请查看编辑。

标签: php laravel laravel-4 pagination


【解决方案1】:

使用fragment()

{{$products->fragment('products')->links();}}

【讨论】:

  • 以上是您问题的答案。如果您有多个问题,请将它们发布在另一个问题中。那样会更容易回答。
  • btw 如何输出演示者?
  • 对不起,我认为您的答案是用于自定义演示者的东西。这行得通:)
猜你喜欢
  • 2017-01-29
  • 1970-01-01
  • 2012-02-16
  • 2014-11-14
  • 1970-01-01
  • 1970-01-01
  • 2015-08-18
  • 2020-01-28
  • 2014-09-13
相关资源
最近更新 更多