【问题标题】:Pagination Wont Display Next Page Results分页不会显示下一页结果
【发布时间】:2017-08-31 06:31:17
【问题描述】:

我正在使用基于LaravelTwigOctoberCMS

October 有一个Scope Pagination 功能,但是缺少我需要的功能,所以我不得不使用 Laravel 来返回结果和分页。

我有一个带有类别和图像数据库记录的厨房。

我正在尝试从 URL 中获取 :category 标识符 nature 以过滤回数据库结果。


问题

代码返回自然图像并显示分页。但是当我点击一个页码时,url 会变为?page=2/2,但页面按钮保持在1 并且记录/图像不会改变。

这就像 php 在下一页重置并再次显示第 1 页结果。


十月CMS

网址
localhost/gallery/nature

标识符
/gallery/:category?latest/:page?


Laravel

获取类别性质的所有图像记录。

我将此代码放入我的页面gallery.htm

$category = $this->param('category');
$this['scopeCategory'] = Gallery::where('category', $category)->paginate(5);

树枝

分页显示图片。

列出图片

{% for image in scopeCategory %}
    <img src="example.com/{{ image.name }}.jpg">
{% endfor %}

简单分页

<< 1 | 2 | 3 | 4 >>

{{ scopeCategory.render|raw }}

自定义分页

← Prev 2 | 3 | 4 | 5 Next →

{% if scopeCategory.LastPage > 1 %}
    <ul class="pagination">
        {% if scopeCategory.CurrentPage > 1 %}
            <li><a href="{{ this.page.baseFileName|page({ (pageParam): (scopeCategory.CurrentPage-1) }) }}">← Prev</a></li>
        {% endif %}
        {% for page in 1..scopeCategory.LastPage %}
            <li class="{{ scopeCategory.CurrentPage == page ? 'active' : null }}">
                <a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
            </li>
        {% endfor %}
        {% if scopeCategory.LastPage > scopeCategory.CurrentPage %}
            <li><a href="{{ this.page.baseFileName|page({ (pageParam): (scopeCategory.CurrentPage+1) }) }}">Next →</a></li>
        {% endif %}
    </ul>
{% endif %}

【问题讨论】:

  • 你试试localhost/gallery/nature:page? 或者你也可以使用可以插入每个模型的构建器组件
  • @Pierre-AndréVullioud 性质:页面?给出相同的结果。构建器的范围不允许我使用 :category 标识符,所以我必须使用 Laravel 代码。

标签: laravel laravel-5 twig octobercms


【解决方案1】:

您可以通过将页码指定为第二个参数(see docs) 将页码直接传递给分页器。以下代码应该可以解决您的问题。

$page= $this->param('page');
$category = $this->param('category');
$this['scopeCategory'] = Gallery::where('category', $category)->paginate(5, $page);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2014-08-22
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    相关资源
    最近更新 更多