| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\admin\controller\platform;
- use app\common\controller\Backend;
- class Platform extends Backend
- {
- // 模型对象
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- // $this->model = new \app\admin\model\third\Platform;
- // $this->model = model('Platform');
- $this->model = model('app\common\model\Platform');
- }
- // 列表页
- public function index()
- {
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = [
- "total" => $total,
- "rows" => $list,
- ];
- return json($result);
- }
- return $this->view->fetch();
- }
- // 添加/编辑
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params['createtime'] = time(); // 自动填充时间戳
- $result = $this->model->save($params);
- if ($result) {
- $this->success();
- } else {
- $this->error(__('Operation failed'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- return $this->view->fetch();
- }
- // 删除
- public function del($ids = "")
- {
- if ($ids) {
- $this->model->destroy($ids);
- $this->success();
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- }
|