public function actionCreate() { $model = new Recommendationcomments(); $data = Yii::$app->request->post(); if (empty($data['phone']) || empty($data['recommendationid']) || empty($data['content'])) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'create recommendationcomment fail!'); } unset($data['phone']); //$model->recommendationid = isset($data['title'])?$data['title']:''; $model->recommendationid = $data['recommendationid']; $model->content = $data['content']; $model->userid = $user->id; $model->created_at = time(); //var_dump(); if ($model->save()) { return array('flag' => 1, 'msg' => 'create recommendationcomment success!'); } else { //var_dump($model->errors); return array('flag' => 0, 'msg' => 'create recommendationcomment fail!'); } }
/** * Creates a new Recommendationcomments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Recommendationcomments(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }