public function actionChat() { $model = new Messages(); if (Yii::$app->request->isAjax) { switch (Yii::$app->request->post('action')) { case 'update': return $this->getMessages(); break; case 'send': if ($model->load(Yii::$app->request->post()) && $model->validate()) { } $model->message = htmlspecialchars($model->message); $model->msg_time = time(); $model->save(); return $this->getMessages(); break; default: return $this->getMessages(); break; } } else { $messages = $model->find()->limit(10)->orderBy('id DESC')->all(); return $this->render('chat', ['model' => $model, 'messages' => $messages]); } }
/** * 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(['site/message', 'id' => '1']); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { $model = new Messages(); if ($model->load(\Yii::$app->request->post())) { if ($model->validate()) { $ch = curl_init(\Yii::$app->request->post()['server'] . 'messages'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['user' => $model->user, 'message' => $model->message])); curl_exec($ch); } } else { return $this->render('index', ['model' => $model]); } }
public function run() { $model = new Messages(); $messages = array_reverse(Messages::findAll(['message_to' => Yii::$app->request->get('id')])); if ($model->load(Yii::$app->request->post())) { if ($model->protectWidget()) { if ($model->validate() and $model->save()) { Yii::$app->getResponse()->redirect(Yii::$app->request->referrer); } } else { Yii::$app->session->setFlash('warning', 'Ошибка! Письмо не отправленно!'); } } return $this->render('messages', ['model' => $model, 'messages' => $messages]); }
/** * 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 (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post())) { $result = $model->save(); if ($result) { return $this->redirect(['view', 'id' => $model->id]); } else { throw new ServerErrorHttpException('添加站内消息模板失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); } } else { throw new ServerErrorHttpException('添加站内消息模板失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); } } else { return $this->render('create', ['model' => $model]); } }