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 data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Recommendationcomments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'userid' => $this->userid, 'recommendationid' => $this->recommendationid, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Finds the Recommendationcomments model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Recommendationcomments the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Recommendationcomments::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getRecommendationcomments() { return $this->hasMany(Recommendationcomments::className(), ['recommendationid' => 'id']); }