Good day to all. I wanted to add this https://github.com/sintret/yii2-chat-adminlte chat on yii2. It does not work although I did everything according to the instructions. I do not know what the problem is. Help who can.

Installed according to the instructions through the composer.

"sintret/yii2-chat-adminlte": "dev-master" 

Created a table

 CREATE TABLE `chat` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `userId` INT(11) DEFAULT NULL, `message` TEXT, `updateDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=INNODB; 

In the controller added

 public function actionSendChat() { $message = $_POST['message']; if ($message) { $model = new Chat; $model -> message = $message; if ($model -> save()) { echo ChatRoom::data(); } else { print_r($model -> getErrors()); exit(0); } } } 

And twist

  <?php echo \sintret\chat\ChatRoom::widget([ 'url' => \yii\helpers\Url::to(['/chat/send-chat']), 'userModel'=> \app\modules\user\models\User::className(), 'userField'=>'avatarImage' ] ); ?> 

Model User Indicated and there is a field as required avatarImage (although if it is not, then the default picture will be installed)

When I open the sendChat.php view form I sendChat.php an error from the controller

 Undefined index: message 

in line

$message = $_POST['message'];

I checked it in another view (users) added

  <?php echo \sintret\chat\ChatRoom::widget([ 'url' => \yii\helpers\Url::to(['/chat/send-chat']), 'userModel'=> \app\modules\user\models\User::className(), 'userField'=>'avatarImage' ] ); ?> 

Shows chat so enter image description here

the $ message variable from the controller equated the word $ message = 'Hello'; and updated the sendChat non-working form, and now this variable is enrolled in the database and appeared in the view (users) that was mentioned above

enter image description here

Help with this problem

  • one
    I can't say it will help you, but please replace $message = $_POST['message']; , on $message = \Yii::$app->request->post('message'); because do it right if you use Yii2. - withoutname
  • @withoutname Thanks problem with $ message has disappear. But it's still not working - Ildar Nasurlaev
  • I think this is the problem of the widget itself. - withoutname
  • one
    @withoutname Maybe you know some chat implemented on yii2? These did not fit phptrends.com/dig_in/yii2-chat - Ildar Nasurlaev

0