将记录重新排序显示为空

问题描述 投票:0回答:1

我正在使用OctoberCMS,Apache和PHP7。

我使用Builder创建了一个自定义插件。

我能够添加记录,一切都很好。除非我按下Reorder records按钮,否则它会显示一个空记录列表。


是否有关于如何设置的指南?

我在看: https://octobercms.com/docs/database/traits#nested-tree https://octobercms.com/docs/api/october/rain/database/traits/nestedtree

我添加到模型中:

use \October\Rain\Database\Traits\NestedTree;

并且到数据库列:

parent_idnest_leftnest_rightnest_depth


我在哪里放$table->integer('parent_id')->nullable();

如果我把它放在模型中它会给出错误Parse error: syntax error, unexpected '$table' (T_VARIABLE), expecting function (T_FUNCTION)


记录

Reorder Records Button


重新排序记录:空列表

Empty Records

laravel octobercms
1个回答
1
投票

首先,你不需要使用nestable,因为我们没有处理trees,似乎有一个指南,但它很简短。

我们可以很高兴与\October\Rain\Database\Traits\Sortable进行排序,因为我们不需要tree我们可以跳过添加这些

use \October\Rain\Database\Traits\NestedTree;
parent_id, nest_left, nest_right, nest_depth

如果我们使用sort_order你需要一个特定的列名trait但是如果我们需要通过在const SORT_ORDER = 'my_sort_order';中定义model我们可以改变它。

由于您已经构建了表格,因此可以使用update your table definition using builder plugin并将sort_order字段添加到您的表格中。

或手动,您可以使用此脚本并将其添加到version.yaml文件[plugins \ hardiksatasiya \ demotest \ updates(分别在您的插件中)]

version.yaml

1.0.19:
    - 'Updated table hardiksatasiya_demotest_sorting'
    - builder_table_update_hardiksatasiya_demotest_sorting_3.php

builder_table_update_hardiksatasiya_demotest_sorting.php

<?php namespace HardikSatasiya\DemoTest\Updates;

use Schema;
use October\Rain\Database\Updates\Migration;

class BuilderTableUpdateHardiksatasiyaDemotestSorting extends Migration
{
    public function up()
    {
        Schema::table('hardiksatasiya_demotest_sorting', function($table)
        {
            $table->integer('sort_order')->default(0)->change();
        });
    }

    public function down()
    {
        Schema::table('hardiksatasiya_demotest_sorting', function($table)
        {
            $table->integer('sort_order')->default(null)->change();
        });
    }
}

现在,将Trait添加到您的模型中

<?php namespace HardikSatasiya\DemoTest\Models;

use Model;

/**
 * Model
 */
class Sort extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\Sortable;

    ....

现在,您可以手动添加所有需要的文件,也可以使用构建器工具。

我更喜欢使用Builder来添加控制器和所需文件

确保你勾选Reorder behavior

enter image description here

要在重新排序列表中显示名称,我们需要将此属性from which field we need to derive a name设置为在排序列表中显示。

enter image description here

它将使用name作为排序属性名称

enter image description here

侧面菜单[plugin.yaml和controllers]

enter image description here

enter image description here

如果您有进一步的疑问请发表评论。

© www.soinside.com 2019 - 2024. All rights reserved.