Пример #1
0
 /**
  * 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())];
     }
 }