bubasuma/yii2-simplechat
Composer 安装命令:
composer require bubasuma/yii2-simplechat
包简介
A simple chat for your yii2 application
README 文档
README
#Yii2 Simple Chat A simple chat for your yii2 application
##Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist bubasuma/yii2-simplechat
or add
"bubasuma/yii2-simplechat": "*"
to the require section of your composer.json file.
##Demo
Once the extension is installed, simply modify your application configuration as follows:
return [ 'bootstrap' => ['simplechat'], 'modules' => [ 'simplechat' => [ 'class' => 'bubasuma\simplechat\Module', ], // ... ], // ... ];
Use the same configuration for your console application:
Note: You need this configuration to access simple chat via command line. You can remove it in production mode.
You can access Simple Chat via command line as follows:
# 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:
# 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:
http://localhost/path/to/index.php?r=messages
or if you have enabled pretty URLs, you may use the following URL:
http://localhost/path/to/index.php/messages
You should see the below:
If not, please check if demo migration has been successfully applied against your database. You can check it by running the following command:
php yii simplechat/start
Note: the command above is accessible only if you have configured your console application as it is recommended above.
##Usage
Extend the main conversation class like follow:
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:
namespace common\models; //... class Message extends \bubasuma\simplechat\db\Message { /** * @inheritDoc */ public function fields() { return [ //... 'text', 'date' => 'created_at', //... ]; } }
Create a controller like follow:
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.
##FAQ
Does this extension work with any template engines other than twig?
Yes. Given that, the default render in yii2 is php, you must indicate explicitly the extension part in view names.
Can I use this extension in a RESTful APIs?
Yes, You can.
Can I use different template engines for rendering in server side and client side?
Yes. But using the same template in both sides remains the best implementation.
bubasuma/yii2-simplechat 适用场景与选型建议
bubasuma/yii2-simplechat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.58k 次下载、GitHub Stars 达 88, 最近一次更新时间为 2015 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「message」 「extension」 「chat」 「yii2」 「conversation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bubasuma/yii2-simplechat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bubasuma/yii2-simplechat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bubasuma/yii2-simplechat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
PHP AMQP Binding Library
Client for the REST API plugin of the OpenFire Server
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 9.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 88
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-11-22