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');
}
}
?>
I've created the reorder view file (reorder.htm
) which contains:
<?= $this->reorderRender() ?>
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
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>
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"
I've tried to trace this error down. It seems like, in \public\modules\backend\behaviors\ReorderController.php
, the reorder()
function is not being called, which means that the prepareVars()
function is also not being called. This prevents the following code from being executed:
$this->vars['reorderToolbarWidget'] = $this->toolbarWidget;
ReorderController.php:: makeToolbarWidget() is being called and seems to be OK. I've checked $this->toolbarWidget, and it seems to contain perfectly good data. (It isn't NULL).
答案 0 :(得分:2)
ReorderController是一种行为,因此它意味着被称为控制器目的地(例如example.com/backend/btruchan/team/members/reorder
)。它没有被编码为以index
函数中的方式调用视图。
在ReorderController源代码中,reorder
函数是调用prepareVars
受保护函数的唯一方法,该函数是为页面定义reorderToolbarWidget
的唯一位置。主机控制器无法提供prepareVars
功能。
因此,不要尝试使用$this->makeView('reorder');
创建视图,而是在_list_toolbar.htm
部分中创建一个指向reorder
目标网址的工具栏按钮。例如:
<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>
当您点击&#34;重新排序会员&#34;按钮,您将被定向到一个新页面,其中包含可以重新排序的记录。
您可以使用_reorder_toolbar.htm
部分在重新订购页面的顶部添加您想要的任何内容。或者,根本不使用它。