public function action_index() { $action = $this->params['action']; if (empty($action)) { $this->display('stourtravel/insurance/index'); } else { if ($action == 'read') { $start = Arr::get($_GET, 'start'); $limit = Arr::get($_GET, 'limit'); $keyword = Arr::get($_GET, 'keyword'); $order = 'order by a.id desc'; if (!empty($keyword)) { $w = "where a.productname like '%{$keyword}%'"; } $sql = "select a.* from sline_insurance as a {$w} {$order} limit {$start},{$limit}"; $totalcount_arr = DB::query(Database::SELECT, "select count(*) as num from sline_insurance a ")->execute()->as_array(); $list = DB::query(Database::SELECT, $sql)->execute()->as_array(); $new_list = array(); foreach ($list as $k => $v) { $new_list[] = $v; } $result['total'] = $totalcount_arr[0]['num']; $result['lists'] = $new_list; $result['success'] = true; echo json_encode($result); } else { if ($action == 'update') { $id = Arr::get($_POST, 'id'); $field = Arr::get($_POST, 'field'); $val = Arr::get($_POST, 'val'); $kindid = Arr::get($_POST, 'kindid'); $model = new Model_Insurance($id); if ($model->loaded()) { $model->{$field} = $val; if ($model->save()) { echo 'ok'; return; } } echo 'no'; } } } }