yii2-chat-adminlte ¶
yii2 chat widget widget admin lte
Requirements ¶
Yii2
Instalation ¶
add via composer : "sintret/yii2-chat-adminlte": "dev-master"
Usage ¶
You just add table chat to your database with this :
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 your view, you must to setup url like the following...
<?php
echo \sintret\chat\ChatRoom::widget([
'url' => \yii\helpers\Url::to(['/chat/send-chat']),
'userModel'=> \app\models\User::className(),
'userField'=>'avatarImage'
]
);
?>
in your controller,
public function actionSendChat() {
if (!empty($_POST)) {
echo \sintret\chat\ChatRoom::sendChat($_POST);
}
}
attribute additional for this widget: url : your controller/action to post message using ajax userModel : your user model class name userField : your avatar image source attribute in your class user model, ex:avatarImage or you can make your virtual property in your class user like this following :
public class User extends blalala {
public function getAvatarImage(){
return Yii::getAlias($this->avatar);
}
}
Resources ¶
external resources for this extension...
- Project page
- Try out a demo you can try with username : kasir and password : jakarta
widget problem
Hello I made a quick try to install your extension but I have a problem :
I added the sendchat action in my user controler
and in the index view of users I added the lien for the chat widget but I suppose that theres an error in this line
it should not be : ...yii\helpers\Url::to(['/chat/send-chat'])]); ?>;
but : ...yii\helpers\Url::to(['/chat/sendchat'])]); ?>;
Now my problem is :
When I type in something its sent to the widget and I can see it in the first time
But as soon as the widget is updated it gets empty
When I type in something again I can see in the widget what was typed before but it gets lost as before
If you could help me to understand would be nice !
solution -> widget problem
Edit controller on this:
public function actionSendChat() { $message = $_POST['message']; if (empty($message)) { echo \sintret\chat\ChatRoom::data(); } elseif($message) { $model = new \sintret\chat\models\Chat; $model->message = $message; if ($model->save()) { echo \sintret\chat\ChatRoom::data(); } else { print_r($model->getErrors()); exit(0); } } }
Phundament 4 and Chat-adminlte
IF you have a error:
Class 'app\models\User' not found
or you use (Phundament 4/dektrium user) we nead edit file:
> sintret/yii2-chat-adminlte/models/Chat.php
edit line 6 form:
use app\models\User;
to:
use dektrium\user\models\User;
i have updated the widgets
Sory long not to reply because i still learn Yii2 :)
you can add param for this widget like this following :
<?php echo \sintret\chat\ChatRoom::widget([ 'url' => \yii\helpers\Url::to(['/chat/send-chat']), 'userModel'=> \app\models\User::className(), 'userField'=>'avatarImage' ] ); ?>
and in your controller :
public function actionSendChat() { echo \sintret\chat\ChatRoom::sendChat($_POST); }
please update composer again with : composer update
thanks all
i cant display the username
Trying to get property of non-object
' . $model->user->username . '
on this line....
Trying to get property of non-object
@janaki you have to following steps :
<?php echo \sintret\chat\ChatRoom::widget([ 'url' => \yii\helpers\Url::to(['/chat/send-chat']), 'userModel'=> \app\models\User::className(), 'userField'=>'avatarImage' ] ); ?>
where userModel is your User class name and userField is your user image source. I wonder if you have no username in your user table
RE:i got error like this .Trying to get property of non-objec
@janaki , i just update this widget
you need to clear your composer using this following : "composer clear-cache" and then pull your composer again, ex: "composer update"
chat with members
In my application,i have to selct one user from db and send msg to them..how to do this???
chat with members
In my application,i have to selct one user from db and send msg to them..how to do this???
RE :chat with members
You can add "mention" like twitter using format, like "@admin" blala blala" your message. but this function will be include in the next versions i will notice in this site.
The userField value and demo
Should that value(avatarImage) be a link(a string attribute) to a file or a file object attribute? I really don't undertand that part well, Help.
Going on the demo page I don't see exactly how I can try it. I really don't understand how to try it on http://sintret.com/, Can any one to give me guidance.
Thanks
Setting unknown property: sintret\chat\ChatRoom::userModel
n D:\wamp\www\doojaviyahtest\vendor\yiisoft\yii2\base\Component.php at line 197
188189190191192193194195196197198199200201202203204205206
$behavior->$name = $value; return; } } } if (method_exists($this, 'get' . $name)) { throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); } else { throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.