Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 从表字段octobercms排序数据_Sorting_Octobercms - Fatal编程技术网

Sorting 从表字段octobercms排序数据

Sorting 从表字段octobercms排序数据,sorting,octobercms,Sorting,Octobercms,我想按列的顺序显示数据,其中数值以OctorberCMS表示 default.htm {% set post = __SELF__.post %} <div class="content">{{ post.content_html|raw }}</div> {% if post.featured_images.count %} <div class="featured-images text-center"> {% for imag

我想按列的顺序显示数据,其中数值以OctorberCMS表示

default.htm

{% set post = __SELF__.post %}

<div class="content">{{ post.content_html|raw }}</div>

{% if post.featured_images.count %}
    <div class="featured-images text-center">
        {% for image in post.featured_images %}
            <p>
                <img
                    data-src="{{ image.filename }}"
                    src="{{ image.path }}"
                    alt="{{ image.description }}"
                    style="max-width: 100%" />
            </p>
        {% endfor %}
    </div>
{% endif %}

<p class="info">
    Posted
    {% if post.categories.count %} in
        {% for category in post.categories %}
            <a href="{{ category.url }}">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
        {% endfor %}
    {% endif %}
    on {{ post.published_at|date('M d, Y') }}
</p>
<p class="info">

    {% for blocks in post.blocks %}  // here the output of this loop must show in order which are given in column in same table which is relation_sort_order
    <b> {{ blocks.title}}</b>

    {{ blocks.content_html|raw }}

    {% endfor %}
</p>
{%set post=\u SELF\u.post%}
{{post.content_html | raw}
{%if post.featured_images.count%}
{%用于post.featured_images%}

{%endfor%} {%endif%}

张贴 {%if post.categories.count%}in {post.categories%中的类别为%s} {%if-not loop.last%},{%endif%} {%endfor%} {%endif%} 在{post.published|date('md,Y')}上

{%for blocks in post.blocks%}//此处,此循环的输出必须按关系\排序\顺序在同一表格的列中给出的顺序显示 {{blocks.title}} {{blocks.content_html | raw} {%endfor%}


如何在relationship_sort_order字段中显示块的数量假定
post
变量是一个自定义模型对象,并且
blocks
是该对象上的一个关系,最好的方法是更新定义
post
对象的模型类中的关系定义

您没有包含这方面的代码,但它可能看起来像这样:

public $hasMany = [
    'blocks' => 'Acme\Blog\Models\Block'
]
默认情况下,您可以将其更新为包含排序顺序,请参见

但简而言之,您可以将上述内容更改为:

public $hasMany = [
    'blocks' => [
        'Acme\Blog\Models\Block', 
        'order' => 'relation_sort_order asc'
    ]
];
然后,无论何时,只要您从
Post
类访问
blocks
关系,它都会自动按该顺序排序