/** * @param $post */ public static function sendChat($post) { if (isset($post['message'])) { $message = $post['message']; } if (isset($post['model'])) { $userModel = $post['model']; } else { $userModel = Yii::$app->getUser()->identityClass; } $model = new Chat(); $model->userModel = $userModel; if ($message) { $model->message = $message; $model->userId = Yii::$app->user->id; /** * сохраняем сообщения в frontend/web/files/chat/chat.txt */ if (!$model->save_to_file()) { print_r($model->getErrors()); exit(0); } else { echo $model->data_from_file(); } //if ($model->save()) { // echo $model->data(); // } else { // print_r($model->getErrors()); // exit(0); // } } else { // echo $model->data(); echo $model->data_from_file(); } }
public function actionDetails($quote) { $chat = new Chat(); if ($chat->load(Yii::$app->request->post())) { $use = new User(); $user = Yii::$app->user->identity->username; $val = $use->findByUsername1($user); $chat->user_id = $val->id; $chat->request_id = $quote; $reqs = Carrequest::find()->where('id=:id', array('id' => $quote))->one(); $chat->dealer_id = $reqs->dealer_id; $chat->sent = 2; if ($chat->save()) { $chat->message = ""; return $this->render('detail', ['quote' => $quote]); } } return $this->render('detail', ['quote' => $quote]); }
<th>Variant</th> <th>Color</th> <th>Delivery</th> <th>On-Road Price</th> </tr> </table> <div class="row"> <div class="col-md-12"> <div class="row"> <div class="col-md-2"> <?php $chats = Chat::find()->where('request_id=:id', array(':id' => $quote))->all(); if (count($chats) > 0) { foreach ($chats as $chat) { if ($chat->sent == 1) { echo $chat->dealer_id . ":" . $chat->message . "<br>"; } else { echo $chat->user_id . ":" . $chat->message . "<br>"; } } } $chat->message = ""; $form = ActiveForm::begin(['id' => 'login-form', 'enableAjaxValidation' => false, 'enableClientValidation' => true]); ?>