/** **创建一个新节点.如果创建成功,浏览器会跳转到该新节点的详情页面. * @return mixed */ public function actionCreate() { $model = new LocationNew(); try { if ($model->load($_POST) && $model->save()) { return $this->redirect(Url::previous()); } elseif (!\Yii::$app->request->isPost) { $model->load($_GET); } } catch (\Exception $e) { $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); $model->addError('_exception', $msg); } return $this->render('create', ['model' => $model]); }
public function createLocationNew() { $location_new = new LocationNew(); $location_new->attributes = ['user_id' => Yii::$app->user->id, 'event_id' => $this->event_id, 'provider_id' => $this->getProvider()->id, 'city' => $this->city, 'title_from_provider' => $this->title_from_provider, 'occur_at' => $this->occur_at]; $details = Yii::$app->map->searchWithTitle($this->city, $this->title_from_provider); if (!$details) { throw new MapWithTitleException('无法获取该位置准确经纬度,请修改位置信息重试'); } $location_new->title_from_API = $details['title']; $location_new->latitude = $details['latitude']; $location_new->longitude = $details['longitude']; if ($this->identity_kind == LocationProvider::IDENTITY_KIND_PEOPLE) { $location_new->is_reliable = $this->isSpaceReliable(); } $location_new->save(); $this->_location_new = $location_new; }