public function findModel($id) { if (($model = Province::findOne($id)) !== null) { return $model; } else { throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
public function run($id) { $id = (int) $id; $output = []; if (($model = \common\models\province\Province::findOne($id)) !== null) { if ($model->delete()) { $output = ['error' => false, 'message' => Yii::t('app', 'Successfully deleted!')]; } } if (empty($output)) { $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')]; } return \yii\helpers\Json::encode($output); }
public function run($search = null, $id = null) { $out = ['more' => false]; if (!is_null($search)) { $query = new Query(); $query->select('[[id]], [[name]] AS [[text]]')->from('{{%province}}')->filterWhere(['like', '[[name]]', $search])->limit(20); $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => Province::findOne($id)->name]; } else { $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')]; } return Json::encode($out); }