首先需要数据表支持我们的排序值存储。
1 2
| ALTER TABLE `fa_config` ADD COLUMN `weight` TINYINT NULL DEFAULT '99' COMMENT '权重' AFTER `extend`;
|
在添加页面的扩展上面增加一个权重的输入框。
application/admin/view/general/config/index.html
1 2 3 4 5 6 7 8 9 10 11 12
| <div class="form-group"> <label for="tip" class="control-label col-xs-12 col-sm-2">权重:</label> <div class="col-xs-12 col-sm-4"> <input type="number" class="form-control" id="weight" name="row[weight]" value="99" min="1" max="99" data-rule="required"/> </div> </div> <div class="form-group"> <label for="extend" class="control-label col-xs-12 col-sm-2">{:__('Extend')}:</label> <div class="col-xs-12 col-sm-4"> <textarea name="row[extend]" id="extend" cols="30" rows="5" class="form-control" data-tip="{:__('Extend tips')}" data-rule="required(extend)" data-msg-extend="当类型为自定义时,扩展属性不能为空"></textarea> </div> </div>
|
修改页面显示的查询处理。
application/admin/controller/general/Config.php
1 2 3 4 5 6 7 8 9 10 11
| /** * 查看 */ public function index() { ... - foreach ($this->model->all() as $k => $v) { + foreach ($this->model->order('weight')->select() as $k => $v) { } ... }
|