public function actionUpdate($id) { //这样获取会将isNewRecord设置为false $model = $this->findModel($id); $enterprises = Enterprise::find()->asArray()->all(); return $this->render('createOrUpdate', ["enterprises" => $enterprises, 'model' => $model]); }
public function actionBind() { $weChatOpenId = Yii::$app->request->get("weChatOpenId"); $model = new WeChatBindForm(); $params = Yii::$app->request->post(); $data = array(); //yii自动生成的form参数是Enterprise["name"]这种形式,获取后就会是在一个Enterprise中 $data["WeChatBindForm"] = $params; if ($model->load($data)) { if ($user = $model->bindWeChat()) { //自动登陆 if (Yii::$app->getUser()->login($user)) { $this->redirect(["notice/show"]); } } } $enterprises = Enterprise::find()->asArray()->all(); $model->weChatOpenId = $weChatOpenId; return $this->render('weChatBind', ["enterprises" => $enterprises, "model" => $model]); }
protected function findModel($id) { if (($model = Enterprise::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** *和enterprise关联 * @return ActiveQuery */ public function getEnterprise() { return $this->hasOne(Enterprise::className(), ['enterprise_id' => 'enterprise_id']); }