clo*_*e45 12 sorting octobercms
I'm excited that the October CMS recently added back-end functionality for sorting records in the list view. But I'm having some trouble getting it to work. The documentation is here. I've followed the direction like so:
In my controller, I implemented the ReorderController:
<?PHP namespace BTruchan\Team\Controllers;
use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Classes\Controller;
use System\Classes\SettingsManager;
class Members extends \Backend\Classes\Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.ReorderController'
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public $reorderConfig = 'config_reorder.yaml';
public $requiredPermissions = ['btruchan.team.manage'];
public function __construct()
{
parent::__construct();
BackendMenu::setContext('BTruchan.Team', 'team');
}
public function index()
{
$this->makeLists();
$this->makeView('reorder');
}
}
?>
Run Code Online (Sandbox Code Playgroud)
I've created the reorder view file (reorder.htm) which contains:
<?= $this->reorderRender() ?>
Run Code Online (Sandbox Code Playgroud)
My config_reorder.yaml file contains:
# ===================================
# Reorder Behavior Config
# ===================================
# Reorder Title
title: Reorder Members
# Attribute name
nameFrom: name
# Model Class name
modelClass: BTruchan\Team\Models\Members
# Toolbar widget configuration
#toolbar:
# Partial for toolbar buttons
# buttons: reorder_toolbar
Run Code Online (Sandbox Code Playgroud)
You'll notice that the reorder_toolbar partial is commented out. That's because I really don't know what's supposed to go in that toolbar. I haven't been able to find any documentation that shows the contents for the _reorder_toolbar.htm file.
Unsurprisingly, with the code commented out, it throws an error:
Undefined variable: reorderToolbarWidget
Some additional information:
It was suggested that I read up on list toolbars here.
So I added the following toolbar partial (named _reorder_toolbar.htm):
<div data-control="toolbar">
<a
href="<?= Backend::url('btruchan/team/members/create') ?>"
class="btn btn-primary oc-icon-plus">
New Team Member
</a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="Delete Team Member: Are you sure?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', false)"
data-stripe-load-indicator>
Delete
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
But I'm still getting an error:
Undefined variable: reorderToolbarWidget /var/www/terrasearch/public/modules/backend/Behaviors/reordercontroller/partials/_container.htm line 1
The code, in October CMS, which that error message is referring is:
<?php if ($reorderToolbarWidget): ?>
<!-- Reorder Toolbar -->
<div id="<?= $this->getId('reorderToolbar') ?>" class="reorder-toolbar">
<?= $reorderToolbarWidget->render() ?>
</div>
<?php endif ?>
<!-- Reorder List -->
<?= Form::open() ?>
<div
id="reorderTreeList"
class="control-treelist"
data-control="treelist"
Run Code Online (Sandbox Code Playgroud)
我试图追踪这个错误.看起来,在\public\modules\backend\behaviors\ReorderController.php中,reorder()函数没有被调用,这意味着该prepareVars()功能也不会被调用.这可以防止执行以下代码:
$this->vars['reorderToolbarWidget'] = $this->toolbarWidget;
Run Code Online (Sandbox Code Playgroud)
正在调用ReorderController.php :: makeToolbarWidget(),似乎没问题.我已经检查了$ this-> toolbarWidget,它似乎包含了非常好的数据.(它不是NULL).
小智 2
ReorderController 是一种行为,因此它应该被称为控制器目标(例如example.com/backend/btruchan/team/members/reorder)。它没有被编码为像在函数中那样作为视图调用index。
在 ReorderController 源中,该reorder函数是调用受保护函数的唯一方法,该函数也是为页面定义的prepareVars唯一位置。主控制器无法使用reorderToolbarWidget该功能。prepareVars
因此,不要尝试使用 创建视图,而是在指向目标 url 的部分$this->makeView('reorder');中创建一个工具栏按钮。例如:_list_toolbar.htmreorder
<div data-control="toolbar">
<a href="<?= Backend::url('btruchan/team/members/create') ?>" class="btn btn-primary oc-icon-plus">New Member</a>
<a href="<?= Backend::url('btruchan/team/members/reorder') ?>" class="btn btn-primary oc-icon-sort">Reorder Members</a>
</div>
Run Code Online (Sandbox Code Playgroud)
当您单击“重新排序成员”按钮时,您将被定向到一个新页面,其中包含可以重新排序的记录。
您可以使用_reorder_toolbar.htm部分在重新排序页面顶部添加您想要的任何内容。或者,根本不使用它。