Yii2 Messenger
Private messages module for yii2, (*1)
Installing
The preferred way to install this extension is through Composer., (*2)
{
"require": {
"nanson/yii2-messenger": "*"
}
}
Migration, (*3)
./yii migrate --migrationPath=@vendor/nanson/yii2-messenger/migrations/
Configure module:, (*4)
'modules' => [
'messenger' => [
'class' => \nanson\messenger\Messenger::className(),
],
],
Usage
Url for contacts list: /messenger/contacts/
., (*5)
, (*6)
Url for messages list: /messenger/contacts/messages/?id={contact_id}
, (*7)
, (*8)
Display contacts list for user with last message., (*9)
<?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, (*10)
<?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., (*11)
<?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., (*12)
<?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']
|