slavkovrn/yii2-chat

用于注册用户聊天的Yii2扩展模块。

1.0.0 2017-08-29 00:10 UTC

This package is auto-updated.

Last update: 2024-09-12 04:12:44 UTC


README

使用先进的模板User模型进行注册用户聊天的Yii2扩展模块。

日志访问者演示页面

Log visitor

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

composer require slavkovrn/yii2-chat

或添加

"slavkovrn/yii2-chat": "*"

到您的 composer.json 文件的require部分。

使用方法

1. 在您的配置中添加ChatModule的链接

return [
    'modules' => [
        'chat' => [
            'class' => 'slavkovrn\chat\ChatModule',
            'numberLastMessages' => 30,
        ],
    ],
]; 
  1. 在您的User模型中,您应该为注册用户定义两个getter来获取名称和图标链接

在我的例子中,这是

namespace app\models;
...
use app\models\Profile;
class User extends ActiveRecord implements IdentityInterface
{
    public function getChatname()
    {
        return Profile::find()->where(['id' => Yii::$app->user->id])->one()['name'];
    }
 
    public function getChaticon()
    {
        return Profile::find()->where(['id' => Yii::$app->user->id])->one()['photo'];
    }
    ...

现在您可以通过http://yoursite.com/chat URL与注册用户聊天

给管理员写评论