вот контроллер:
Код: Выделить всё
<?php public function actionChat()
{
if (Yii::$app->request->isAjax) {
$data=(Yii::$app->request->post());
$chat= new Chat();
if( $chat->load($data) ){
if( $chat->save() ){
Yii::$app->session->setFlash('success', 'Данные приняты');
}else{
Yii::$app->session->setFlash('error', 'Ошибка');
}
}
$message = Message::find();
$pagination = new Pagination(['totalCount' => $message->count(),
'defaultPageSize'=>20]);
$message = $message->offset( $pagination->offset )->limit( $pagination->limit )->all();
return [
'message' => $message,
'code' => 200,
];
}
return $this->render('chat', ['message' => $message,'pagination' => $pagination]);
}
Код: Выделить всё
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\widgets\Pjax;?>
<?php Pjax::begin(); ?>
<?foreach($message as $messages){
echo $messages->fromm.'<br>'.
$messages->too.'<br>'.
$messages->text.'<br>';
};?>
<?php Pjax::end(); ?>
<?php $form = ActiveForm::begin(['options' => ['id' => 'inputform', 'options' => ['class' => 'inputform','enctype' => 'multipart/form-data']]])?>
<?= $form->field($model, 'fromm')?>
<?= $form->field($model, 'too')?>
<?= $form->field($model, 'text')->textarea(['rows' => '6'])?>
<?= Html::submitButton('Отправить', ['class' => 'btn btn-success'])?>
<?php ActiveForm::end() ?>