PHP code example of gofmanaa / yii2-simplechat

1. Go to this page and download the library: Download gofmanaa/yii2-simplechat 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/ */

    

gofmanaa / yii2-simplechat example snippets


return [
    'bootstrap' => ['simplechat'],
    'modules' => [
        'simplechat' => [
            'class' => 'bubasuma\simplechat\Module',
        ],
        // ...
    ],
    // ...
];

namespace common\models;

//...
use bubasuma\simplechat\db\Model;
use common\models\User;
use yii\db\ActiveQuery;
//...

class Message extends Model
{
    public function getContact()
    {
        return $this->hasOne(User::className(), ['id' => 'contact_id']);
    }
    
    /**
     * @inheritDoc
     */
    public static function conversations($userId)
    {
        return parent::conversations($userId)->with([
            //...
            'contact' => function ($contact) {
                /**@var $contact ActiveQuery * */
                $contact->with([
                    //...
                ])->select(['id', ]);
            },
            //...
        ]);
    }
}

namespace frontend\controllers;

//...
use yii\web\Controller;
use yii\helpers\StringHelper;
use common\models\Message;
use bubasuma\simplechat\controllers\ControllerTrait;
//...

class MessageController extends Controller
{
    use ControllerTrait;
    
    /**
     * @return string
     */
    public function getModelClass()
    {
        return Message::className();
    }
    
    /**
     * @inheritDoc
     */
    public function formatMessage($model)
    {
        //...
        return $model;
    }

    /**
     * @inheritDoc
     */
    public function formatConversation($model)
    {
        //...
        $model['text'] = StringHelper::truncate($model['text'], 20);
        //...
        return $model;
    }
}

# You can specify how many fixtures per user and message you need by the --users and --messages options
php yii simplechat/start --users=50 --messages=10000
php yii simplechat/reset --users=20 --messages=5000

# You can specify in what language to generate fixtures by the --language option. Thanks to yii2-faker
php yii simplechat/start --language="ru_RU"
php yii simplechat/reset --language="fr_FR"


http://localhost/path/to/index.php?r=messages/2

php yii simplechat/start