/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $message = new Message(); if ($message->load(Yii::$app->request->post()) && $message->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['message' => $message]); } }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Message(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'User_id' => $model->User_id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionSaveMasseges() { $model = new Message(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file && $model->validate()) { $path = 'uploads/' . md5(microtime()) . '.' . $model->file->extension; $model->file->saveAs($path); } } $model->saveMassage($path); return $this->redirect('/site/index'); }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Message(); $data = Yii::$app->request->post(); $ret = $model->load($data); $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($ret && $model->upload() && $model->save()) { if (isset($data['Message']['categoryID'])) { foreach ($data['Message']['categoryID'] as $val) { $relation = new CategoryRelationship(); $relation->media = $model->ID; $relation->category = $val; $relation->type = 2; $relation->save(); } } return $this->redirect(['view', 'id' => $model->ID]); } else { return $this->render('create', ['model' => $model]); } }
public function actionView($id) { $message = Message::findOne($id); $messages = Message::find()->where(['number' => $message->number])->all(); $model = Project::findOne($message->project_id); $reply = new Message(); foreach ($messages as $item) { $item->status = 4; $item->save(); } if ($reply->load(Yii::$app->request->post()) && $reply->validate()) { // $reply->user_id = $reply->project_id = $message->project_id; $reply->status = 1; $reply->time = time(); $reply->type = 'text'; $reply->save(); // Send twilio Text through project model $model->sendText([$message->user_id], $reply->message); Yii::$app->session->setFlash('success', 'Message Sent'); $this->redirect(['/project/messages', 'id' => $message->project_id]); } return $this->render('view', ['message' => $message, 'messages' => $messages, 'model' => $model, 'reply' => $reply]); }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionAjaxSendMessage() { Yii::$app->response->format = Response::FORMAT_JSON; $model = new Message(); $model->sender_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->get()) && $model->save()) { return ['status' => 1, 'message' => 'message sent successfully to ' . $model->receiver->full_name]; } else { /* return $this->render('create', [ 'model' => $model, 'new_messages' => 10 ]);*/ return ['status' => 0, 'message' => 'request error : ' . print_r($model->getErrors())]; } }