request->isAjax) { Yii::$app->response->format = 'json'; $request = Yii::$app->request; $page = $request->get('page', 1); $limit = $request->get('limit', 10); $name = $request->get('category_name', ''); $where = []; if($name){ $where[] = ['name' => $name]; } $data = CoinApplicationCategory::getList($page, $limit, $where); return $data; } return $this->render('index'); } /** * 添加一个application category */ public function actionAddAndEdit() { if (Yii::$app->request->isPost) { Yii::$app->response->format = 'json'; $fields = ['id','name','sort','icon','banner','banner_url']; $params = $this->initParams(Yii::$app->request->post(), $fields); $application_category = new CoinApplicationCategoryForm(); if($params['id']){ //edit $application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT); $application_category->load($params,''); return $application_category->edit(); }else{ $application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_ADD); $application_category->load($params,''); return $application_category->add(); } } } /** * @return array * @throws \Throwable * @throws \yii\db\StaleObjectException */ public function actionDelete() { Yii::$app->response->format = 'json'; $id = Yii::$app->request->get('id'); if ($id) { $application_category = new CoinApplicationCategoryForm(); return $application_category->del($id); } return ['code' => 1, 'msg' => 'failed']; } }