Exemplo n.º 1
0
 /**
  * 查询省份名称
  * @param $provinceId
  * @return mixed
  * @throws \Exception
  */
 public static function findNameByProvinceId($provinceId)
 {
     $result = Province::getDb()->cache(function () use($provinceId) {
         return Province::findOne($provinceId);
     }, 3600);
     if ($result) {
         return $result->name;
     } else {
         return null;
     }
 }
 public function actionArea()
 {
     $request = Yii::$app->request;
     if ($request->isPost) {
         $id = $request->post('id');
         $name = $request->post('name');
         if ($id) {
             $province = Province::findOne($id);
             CommonFunctions::createAlertMessage("修改成功", "success");
         } else {
             $province = new Province();
             CommonFunctions::createAlertMessage("添加成功", "success");
         }
         $province->name = $name;
         if (!$province->save()) {
             throw new Exception("Basic Date area save error");
         }
         return $this->redirect(['basic-data/area']);
     }
     $models = Province::findAllForObject();
     return $this->render('area', ['models' => $models]);
 }
 /**
  * Finds the Province model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Province the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Province::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }