定制 denisbespyatov/directchat 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

denisbespyatov/directchat

最新稳定版本:v1.0.0.1

Composer 安装命令:

composer require denisbespyatov/directchat

包简介

Yii2 direct chat

README 文档

README

#Yii2 Direct chat A simple chat for your yii2 application

##Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist denisbespyatov/directchat

or add

"denisbespyatov/directchat": "*"

to the require section of your composer.json file.

##Demo

Once the extension is installed, simply modify your application configuration as follows:

return [
    'bootstrap' => ['directchat'],
    'modules' => [
        'directchat' => [
            'class' => 'denisbespyatov\directchat\Module',
        ],
        // ...
    ],
    // ...
];

##Usage

Extend the main conversation class like follow:

namespace common\models;

use common\models\User;
//...

class Conversation extends \denisbespyatov\directchat\db\Conversation
{
    public function getContact()
    {
        return $this->hasOne(User::className(), ['id' => 'contact_id']);
    }
    
    /**
     * @inheritDoc
     */
    protected static function baseQuery($userId)
    {
        return parent::baseQuery($userId) ->with(['contact.profile']);
    }
    
    /**
     * @inheritDoc
     */
    public function fields()
    {
        return [
            //...
            'contact' => function ($model) {
                return $model['contact'];
            },
            'deleteUrl',
            'readUrl',
            'unreadUrl',
            //...
        ];
    }
}

Extend the main message class like follow:

namespace common\models;

//...

class Message extends \denisbespyatov\directchat\db\Message
{
    /**
     * @inheritDoc
     */
    public function fields()
    {
        return [
            //...
            'text',
            'date' => 'created_at',
            //...
        ];
    }
}

Create a controller like follow:

namespace frontend\controllers;

//...
use yii\web\Controller;
use common\models\Conversation;
use common\models\Message;
use denisbespyatov\directchat\controllers\ControllerTrait;
//...

class MessageController extends Controller
{
    use ControllerTrait;
    
    /**
     * @return string
     */
    public function getMessageClass()
    {
        return Message::className();
    }

    /**
     * @return string
     */
    public function getConversationClass()
    {
        return Conversation::className();
    }
}

Note: If you are using this extension in your frontend application, you can find the usage of widgets in index.twig.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-19