Esempio n. 1
0
 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]);
     }
 }
Esempio n. 3
0
 public function makeContactRequest(ContactRequest $req)
 {
     $msg = new Messages();
     $msg->name = $req->input('name');
     $msg->email = $req->input('email');
     $msg->message = $req->input('message');
     $msg->status = 0;
     if ($msg->save()) {
         return redirect()->back()->with('msg', 'ok');
     }
 }
Esempio n. 4
0
 public function actionAddmessage()
 {
     $date = date('Y-m-d H:i:s');
     $model = new Messages();
     $model->congrats = $_POST['congrats'];
     $model->signature = $_POST['signature'];
     $model->address = $_POST['address'];
     $model->email = $_POST['email'];
     $model->card = $_POST['card'];
     $model->dateCreated = $date;
     echo $model->save() ? 'true' : 'false';
 }
 /**
  * Store a newly created resource in storage.
  * POST
  * @return Response
  */
 public function store()
 {
     $uid_to = Input::get('uid_to');
     $uid_from = Input::get('uid_from');
     $message = Input::get('message');
     $Messages = new Messages();
     $Messages->uid_to = $following_uid;
     $Messages->uid_from = $uid;
     $Messages->message = $message;
     $Messages->save();
     //return Users::where('uid',$uid)->get();
     return '';
 }
Esempio n. 6
0
 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]);
     }
 }