Skip to content

Commit a035244

Browse files
authored
Update README.md
1 parent 4406716 commit a035244

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
11
# yii2-sse
22
Yii2 SSE is a wrapper for the library libSSE-php. Its used for managing Server Sent Events in Yii2.
3+
4+
## Installation
5+
You'll be installing this package through composer.
6+
7+
Run this command within your project folder: `composer require odannyc/yii2-sse`
8+
9+
## Usage
10+
*These steps are for the simple/basic Yii2 project.*
11+
12+
Edit your `web.php` config file which is located usually in `app/config/web.php`
13+
14+
``` php
15+
'components' => [
16+
...
17+
'sse' => [
18+
'class' => \odannyc\Yii2SSE\LibSSE::class
19+
]
20+
...
21+
];
22+
```
23+
24+
You'll have to create a handler for your SSE instance. Usually located in `app/sse/`.
25+
```php
26+
use odannyc\Yii2SSE\SSEBase;
27+
28+
class MessageEventHandler extends SSEBase
29+
{
30+
public function check()
31+
{
32+
return true;
33+
}
34+
35+
public function update()
36+
{
37+
return "Something Cool";
38+
}
39+
}
40+
```
41+
42+
Then, anywhere in your controller:
43+
44+
``` php
45+
public function actionIndex()
46+
{
47+
$sse = Yii::$app->sse;
48+
$sse->addEventListener('message', new MessageEventHandler());
49+
$sse->start();
50+
}
51+
```
52+
53+
## More information
54+
For more information on using the SSE functionalites of this package visit:
55+
https://github.com/licson0729/libSSE-php

0 commit comments

Comments
 (0)