render('index'); } public function actionIndexJson() { Yii::$app->response->format = Response::FORMAT_JSON; $request = Yii::$app->request; $offset = $request->get('offset',0); $limit = $request->get('limit', 10); $query = ZhongjiYingxiao::find() ->where('is_delete=0') ->orderBy('id desc'); $total = $query->count(); $query = $query->offset($offset)->limit($limit); $items = $query->all(); $data = []; $data['total'] = $total; $data['rows'] = []; foreach($items as $item) { $row = $item->toArray(); $data['rows'][] = $row; } return $data; } public function actionAdd() { return $this->render('add'); } public function actionEdit() { $request = Yii::$app->request; $id = $request->get('id'); $info = ZhongjiYingxiao::findOne(['id'=>$id]); return $this->render('edit', [ 'info' => $info ]); } public function actionSave() { Yii::$app->response->format = Response::FORMAT_JSON; $request = Yii::$app->request; $result = array(); $result['success'] = false; $result['msg'] = '保存失败'; if($request->isPost) { $op = $request->post('op', 'add'); $name = $request->post('name'); $begin_date = $request->post('begin_date'); $begin_time = $request->post('begin_time'); $end_date = $request->post('end_date'); $end_time = $request->post('end_time'); $remark = $request->post('remark'); if($op == 'add') { $item = new ZhongjiYingxiao(); $item->celuo_name = $name; $item->begin_date = $begin_date.' '.$begin_time.':00'; $item->end_date = $end_date.' '.$end_time.':00'; $item->is_delete = 0; $item->remark = $remark; $item->save(); $result['success'] = true; $result['msg'] = '保存成功'; return $result; } else { $id = $request->post('id'); $item = ZhongjiYingxiao::findOne(['id'=>$id]); if($item) { $item->celuo_name = $name; $item->begin_date = $begin_date.' '.$begin_time.':00'; $item->end_date = $end_date.' '.$end_time.':00'; $item->remark = $remark; $item->save(); $result['success'] = true; $result['msg'] = '保存成功'; return $result; } } } return $result; } }