public function action_index() { $action = $this->params['action']; if (empty($action)) { $this->display('stourtravel/comment/list'); } else { if ($action == 'read') { $start = Arr::get($_GET, 'start'); $limit = Arr::get($_GET, 'limit'); $keyword = Arr::get($_GET, 'keyword'); $order = 'order by a.addtime desc'; $sql = "select a.* from sline_comment as a {$order} limit {$start},{$limit}"; //echo $sql; $totalcount_arr = DB::query(Database::SELECT, "select count(*) as num from sline_comment a ")->execute()->as_array(); $list = DB::query(Database::SELECT, $sql)->execute()->as_array(); $new_list = array(); foreach ($list as $k => $v) { $v['productname'] = ORM::factory('question')->getProductName($v['articleid'], $v['typeid']); $v['nickname'] = Model_Comment::getMemberName($v['memberid']); $v['modulename'] = Model_Comment::getPinlunModule($v['typeid']); $new_list[] = $v; } $result['total'] = $totalcount_arr[0]['num']; $result['lists'] = $new_list; $result['success'] = true; echo json_encode($result); } else { if ($action == 'save') { } else { if ($action == 'delete') { $rawdata = file_get_contents('php://input'); $data = json_decode($rawdata); $id = $data->id; if (is_numeric($id)) { $model = ORM::factory('comment', $id); $model->delete(); } } else { if ($action == 'update') { $id = Arr::get($_POST, 'id'); $field = Arr::get($_POST, 'field'); $val = Arr::get($_POST, 'val'); if (is_numeric($id)) { $model = ORM::factory('comment', $id); } if ($model->id) { $model->{$field} = $val; $model->save(); if ($model->saved()) { echo 'ok'; } else { echo 'no'; } } } } } } } }