/** * Creates a new Messages model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Messages(); 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 actionSend() { $data = Yii::$app->request->post(); $msg = new Messages(); $phone = Users::findOne(['phone' => $data['phone']]); // $msg->userid = Yii::$app->user->id; $msg->userid = $phone['id']; $msg->content = $data['content']; $msg->created_at = time(); $msg->pictures = $data['pictures']; if ($msg->save()) { return array('flag' => 1, 'msg' => 'Send success!'); } else { return array('flag' => 0, 'msg' => 'Send fail!'); } }