-
按钮
-
{ field: 'buttons', "120px", title: __('按钮组'), table: table, events: Table.api.events.operate, buttons: [ { name: 'fahuo', text: __('发货'), title: __('发货'), // classname: 'btn btn-xs btn-primary btn-dialog', classname: 'btn btn-xs btn-warning btn-dialog', icon: 'fa fa-list', url: 'jifen/jifenorders/fahuo', callback: function (data) { Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"}); }, visible: function (row) { //返回true时按钮显示,返回false隐藏 return true; } } ], formatter: Table.api.formatter.buttons }
-
js绑定事件
-
fahuo: function () { Controller.api.bindevent(); },
-
控制器
-
public function fahuo($ids) { $row = $this->model->get(['id' => $ids]); if (!$row) { $this->error(__('No Results were found')); } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 // if ($this->modelValidate) { // $name = str_replace("\model\", "\validate\", get_class($this->model)); // $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.silver' : $name) : $this->modelValidate; // $row->validateFailException(true)->validate($validate); // } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were updated')); } } $this->error(__('Parameter %s can not be empty', '')); } $res=$row->toArray(); $this->view->assign("order_id", $res['order_id']); $this->view->assign("row", $res); return $this->view->fetch(); }
-
页面
-
<form id="silver-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> <div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('kuaidi')}:</label> <div class="col-xs-12 col-sm-8"> <input id="c-kuaidi" class="form-control" name="row[kuaidi]" type="text" value="{$row.kuaidi|htmlentities}"> </div> </div> <div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('danhao')}:</label> <div class="col-xs-12 col-sm-8"> <input id="c-danhao" class="form-control" name="row[danhao]" type="text" value="{$row.danhao|htmlentities}"> </div> </div> <div class="form-group layer-footer"> <label class="control-label col-xs-12 col-sm-2"></label> <div class="col-xs-12 col-sm-8"> <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button> <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> </div> </div> </form>