1. Go to this page and download the library: Download denisbespyatov/directchat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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',
//...
];
}
}
namespace common\models;
//...
class Message extends \denisbespyatov\directchat\db\Message
{
/**
* @inheritDoc
*/
public function fields()
{
return [
//...
'text',
'date' => 'created_at',
//...
];
}
}
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();
}
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.