2017 © Pedro Peláez
 

yii2-extension yii2-simplechat

A simple chat for your yii2 application

image

bubasuma/yii2-simplechat

A simple chat for your yii2 application

  • Saturday, June 17, 2017
  • by bubasuma
  • Repository
  • 17 Watchers
  • 62 Stars
  • 2,780 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 31 Forks
  • 11 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

Yii2 Simple Chat

A simple chat for your yii2 application, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist bubasuma/yii2-simplechat

or add, (*4)

"bubasuma/yii2-simplechat": "*"

to the require section of your composer.json file., (*5)

Demo

Once the extension is installed, simply modify your application configuration as follows:, (*6)

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

Use the same configuration for your console application:, (*7)

Note: You need this configuration to access simple chat via command line. You can remove it in production mode., (*8)

You can access Simple Chat via command line as follows:, (*9)

# change path to your application's base path
cd path/to/AppBasePath

# show available commands
php yii simplechat

# create test tables, generates and load fixtures
php yii simplechat/start

# unload fixtures
php yii simplechat/clean

# unload fixtures and load them again
php yii simplechat/reset

# unload fixtures and drop test tables
php yii simplechat/stop

You can specify different options of the start and reset command:, (*10)

# 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"

You can then access Simple Chat through the following URL:, (*11)

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

or if you have enabled pretty URLs, you may use the following URL:, (*12)

http://localhost/path/to/index.php/messages

You should see the below:, (*13)

yii simple chat demo page, (*14)

If not, please check if demo migration has been successfully applied against your database. You can check it by running the following command:, (*15)

php yii simplechat/start

Note: the command above is accessible only if you have configured your console application as it is recommended above., (*16)

Usage

Extend the main conversation class like follow:, (*17)

namespace common\models;

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

class Conversation extends \bubasuma\simplechat\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:, (*18)

namespace common\models;

//...

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

Create a controller like follow:, (*19)

namespace frontend\controllers;

//...
use yii\web\Controller;
use common\models\Conversation;
use common\models\Message;
use bubasuma\simplechat\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., (*20)

FAQ

Does this extension work with any template engines other than twig?, (*21)

Yes. Given that, the default render in yii2 is php, you must indicate explicitly the extension part in view names., (*22)

Can I use this extension in a RESTful APIs?, (*23)

Yes, You can., (*24)

Can I use different template engines for rendering in server side and client side?, (*25)

Yes. But using the same template in both sides remains the best implementation., (*26)

Wiki

Using twig as template engine, (*27)

Pusher integration, (*28)

The Versions

17/06 2017

v2.1.x-dev

2.1.9999999.9999999-dev

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Buba Suma

extension yii2 message chat conversation

06/11 2016

dev-master

9999999-dev

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Buba Suma

extension yii2 message chat conversation

19/06 2016

v2.0.0

2.0.0.0

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Buba Suma

extension yii2 message chat conversation

29/05 2016

v2.0.0-beta

2.0.0.0-beta

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Buba Suma

extension yii2 message chat conversation

24/01 2016

v2.0.0-alpha

2.0.0.0-alpha

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

by Buba Suma

extension yii2 message chat conversation

23/01 2016

v1.0.0

1.0.0.0

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

by Buba Suma

extension yii2 message chat conversation

13/12 2015

v1.0.0-rc

1.0.0.0-RC

A simple chat for your yii2 application

  Sources   Download

BSD-3-Clause

The Requires

 

by Buba Suma

extension yii2 message chat conversation