October/Winter CMS插件开发之拖拉排序
拖拉排序需要用到系统的Sorting Records排序功能,分别有三个内置Model来支持此功能,分别是:
NestedTree需要使用parent_id,nest_left,nest_right和nest_depth这几个字段,树形有层级的多维排序SimpleTree同上,简易版的树形结构Sortable最为简单的一维排序,也是最常用的,需要在表中建立sort_order字段
为插件添加排序功能
在后台自行创建的步骤,首先需要在database中添加sort_order字段,并把默认值设置为0,接下来在添加插件的controller的时候把Recorder controller behavior勾上,在添加完之后需要做一些设置:

这个Attribute name一定要设置,不然在排序设置页是看不到标题的。
代码部分
下面所有代码除了
Model部分需要手动定义类型外,其它部分都是自动生成,根据情况修改即可。
Model
到插件下需要使用排序的Model中添加排序的类型,这里根据情况可以换成上面三个中的一个
class User extends Model
{
use \October\Rain\Database\Traits\Sortable;
}Controller
主文件里面$implement和$reorderConfig引用的部分
public $implement = [ 'Backend\Behaviors\ListController', 'Backend\Behaviors\FormController', 'Backend\Behaviors\ReorderController' ];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public $reorderConfig = 'config_reorder.yaml';Controller子目录
_list_toolbar.htm顶部的排序按钮_reorder_toolbar.htm进入排序页面后的返回按钮config_reorder.yaml配置文件
最终效果


最后引用一下国外网友描述的排序功能操作流程
- Add to your model October\Rain\Database\Traits\Sortable
- Add to your controller $implement & $reorderConfig
- Create config_reorder.yaml
- Add reorder button to _list_toolbar.htm with link .../reorder (similar as for create)
- Create reorder.html
- Add toolbar (_reorder_toolbar.htm) for reorder.html page with back button In general thats it.