/** * Creates a new Usertocards model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Usertocards(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $data = Yii::$app->request->post(); if (empty($data['phone']) || empty($data['cardnumber']) || empty($data['name']) || empty('idcard') || empty('lphone') || empty('location')) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'user not exist!'); } $model = new Usertocards(); $model['userid'] = $user['id']; foreach (array('cardnumber', 'name', 'idcard', 'lphone', 'location', 'bankname', 'bankcode') as $item) { $model[$item] = $data[$item]; } if ($model->save()) { return array('flag' => 1, 'msg' => 'create success!'); } else { return array('flag' => 0, 'err' => $model->errors, 'msg' => 'create failure!'); } }