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 actionList() { $params = Yii::$app->request->queryParams; $limit = $params["iDisplayLength"]; $offset = $params["iDisplayStart"]; $sEcho = $params["sEcho"]; $query = Enterprise::find(); $count = $query->count(); $aaData = $query->with(["admin" => function ($query) { $query->addSelect(["enterprise_id", "name"]); }])->asArray()->limit($limit)->offset($offset)->all(); \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['success' => true, 'aaData' => $aaData, "iTotalRecords" => $count, "iTotalDisplayRecords" => $count, "sEcho" => $sEcho]; }
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]); }