protected function findModel($id) { if (($model = DictCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function checkExist() { if ($this->isNewRecord || $this->id != $this->oldAttributes['id']) { $ret = DictCategory::findOne($this->id); return $ret !== null; } return false; }
public function actionUpdate($id) { $model = $this->findModel($id); $pid = $model->parent_id; $catid = $model->category_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { CacheUtility::createDictCache(); return $this->redirect(['index', 'pid' => $pid, 'catid' => $catid]); } else { $locals = []; $locals['model'] = $model; $locals['parent'] = $this->findModel($pid); $locals['parents'] = Dict::getParents($pid); $locals['category'] = DictCategory::findOne($catid); return $this->render('update', $locals); } }