Private messages module for yii2
The preferred way to install this extension is through Composer.
{
"require": {
"nanson/yii2-messenger": "*"
}
}
Migration
./yii migrate --migrationPath=@vendor/nanson/yii2-messenger/migrations/
Configure module:
'modules' => [
'messenger' => [
'class' => \nanson\messenger\Messenger::className(),
],
],
Url for contacts list: /messenger/contacts/
.
Url for messages list: /messenger/contacts/messages/?id={contact_id}
Display contacts list for user with last message.
<?php
echo \nanson\messenger\widgets\Contacts::widget();
?>
Option | Type | Description |
---|---|---|
userId | integer | User ID. Default: \Yii::$app->user->id |
tpl | string | Widget template. Default: create |
options | array | The HTML attributes for the widget wrapper tag. Default: [] |
pageSize | integer | Contacts per page. Default: 10 |
defaultOrder | array | Default contacts order Default: ['last_message_id' => SORT_DESC] |
viewRoute | string | Route to messages. Default: /messenger/contacts/messages |
dataProviderOptions | array | Options for yii\data\ActiveDataProvider . Default: [] |
queryModifier | callable | Function to modify ActiveDataProvider query. Default: null |
skinAsset | string | Skin Asset Bundles class. Default: null |
Display user messages with current contact
<?php
echo \nanson\messenger\widgets\Messages::widget([
'contactId' => $contactId,
]);
?>
Option | Type | Description |
---|---|---|
contactId | integer | Contact ID. |
userId | integer | User ID. Default: \Yii::$app->user->id |
tpl | string | Widget template. Default: messages |
options | array | The HTML attributes for the widget wrapper tag. Default: [] |
pageSize | integer | Messages per page. Default: 10 |
defaultOrder | array | Default contacts order Default: ['created_at' => SORT_DESC] |
dataProviderOptions | array | Options for yii\data\ActiveDataProvider . Default: [] |
queryModifier | callable | Function to modify ActiveDataProvider query. Default: null |
skinAsset | string | Skin Asset Bundles class. Default: null |
Display form to message creation.
<?php
echo \nanson\messenger\widgets\AddMessage::widget([
'contactId' => $contactId,
'pjaxId' => "pjaxMessages",
]);
?>
Option | Type | Description |
---|---|---|
contactId | integer | Contact ID. |
userId | integer | User ID. Default: \Yii::$app->user->id |
tpl | string | Widget template. Default: create |
options | array | The HTML attributes for the widget wrapper tag. Default: [] |
formOptions | array | The HTML attributes for the widget form. Default: [] |
route | string | Route to create message action. Default: /messenger/rest/create |
skinAsset | string | Skin Asset Bundles class. Default: null |
pjaxId | string | Pjax widget Id. If specified, pjax will be reloaded after message creation. Default: null |
fancySelector | string | Fancybox selector. If specified, widget will be rendered as Fancybox. https://github.com/newerton/yii2-fancybox Default: null |
fancyOptions | array | Fancybox widget options. Default: null |
Display count unreaded messages for user.
<?php
echo \nanson\messenger\widgets\Counter::widget();
?>
Option | Type | Description |
---|---|---|
route | string | Route to action. Default: /messenger/rest/count |
timeout | integer | Update timout. Default: 30 |
tag | string | Counter html tag. Default: span |
options | array | The HTML attributes for the counter tag. Default: ['class' => 'badge'] |