public function actionSend() { if (\Yii::$app->request->post('selection')) { foreach (\Yii::$app->request->post('selection') as $value) { $model = new Message(); $model->message = \Yii::$app->request->post('message'); $model->sender_id = \Yii::$app->user->id; $model->receiver_id = $value; $model->save(); } \Yii::$app->getSession()->setFlash('success', 'Message Sent'); return $this->redirect(['event/' . \Yii::$app->request->post('event_id')]); } else { \Yii::$app->getSession()->setFlash('danger', 'Please select users to send message'); return $this->redirect(['event/' . \Yii::$app->request->post('event_id')]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Message::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, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'message', $this->message]); return $dataProvider; }
public function getMessage() { return $this->hasOne(Message::className(), ['id' => 'user_id'], ['id' => 'sender_id']); }
/** * * Callback function only use for the sendMsg; */ public function saveMsg($res, $param = []) { if (!$res['error']['res'] && isset($res['error'][0])) { $this->resMessage = $res['error']; return false; } $content = ''; if ($msgs = isset($res['error']['returnMsg']) ? $res['error']['returnMsg'] : '') { $datas = explode('|', $msgs); if ($datas[0] == 'ERROR') { $content = $datas[1] . '|'; } } $content .= $res['content']; $msg = new Message(); $msg->msg_type = 'verify_code'; $msg->content = $content; $msg->mobile = $param['mobile']; $msg->code = $param['code']; $msg->save(); }
/** * Finds the Review model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Review the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Message::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }