Skip to content

Commit ec51822

Browse files
committed
README.md
1 parent 02815f7 commit ec51822

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

README.md

+50-32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Yii2 LTI Tool Provider
33

44
LTI Tool Provider library for Yii2
55

6+
[![Latest Stable Version](https://poser.pugx.org/izumi-kun/yii2-lti-tool-provider/v/stable)](https://packagist.org/packages/izumi-kun/yii2-lti-tool-provider)
7+
[![Total Downloads](https://poser.pugx.org/izumi-kun/yii2-lti-tool-provider/downloads)](https://packagist.org/packages/izumi-kun/yii2-lti-tool-provider)
8+
[![License](https://poser.pugx.org/izumi-kun/yii2-lti-tool-provider/license)](https://packagist.org/packages/izumi-kun/yii2-lti-tool-provider)
9+
610
Installation
711
------------
812

@@ -14,40 +18,54 @@ Usage
1418
-----
1519

1620
1. Add namespaced migrations: `izumi\yii2lti\migrations`. Apply new migrations.
17-
2. Add module to web-config:
1821

19-
```php
20-
$config = [
21-
'modules' => [
22-
'lti' => [
23-
'class' => \izumi\yii2lti\Module::class,
22+
2. Add module to web-config:
23+
```php
24+
$config = [
25+
'modules' => [
26+
'lti' => [
27+
'class' => \izumi\yii2lti\Module::class,
28+
],
2429
],
25-
],
26-
];
27-
```
28-
29-
3. Connect action:
30+
];
31+
```
3032

31-
```php
32-
public function actionLtiConnect()
33+
3. Create connect action:
34+
```php
35+
use izumi\yii2lti\Module;
36+
use izumi\yii2lti\ToolProviderEvent;
37+
use Yii;
38+
use yii\web\Controller;
39+
40+
class ConnectController extends Controller
3341
{
34-
/* @var Module $module */
35-
$module = Yii::$app->getModule('lti');
36-
37-
// launch action
38-
$module->on(Module::EVENT_LAUNCH, function (ToolProviderEvent $event){
39-
$tool = $event->sender;
40-
41-
// $userPk can be used for user identity
42-
$userPk = $tool->user->getRecordId();
43-
$isAdmin = $tool->user->isStaff() || $tool->user->isAdmin();
44-
45-
Yii::$app->session->set('isAdmin', $isAdmin);
46-
Yii::$app->session->set('userPk', $userPk);
47-
48-
$this->redirect($isAdmin ? ['site/admin'] : ['site/index']);
49-
});
50-
51-
return $module->handleRequest();
42+
public $enableCsrfValidation = false;
43+
44+
public function actionIndex()
45+
{
46+
/* @var Module $module */
47+
$module = Yii::$app->getModule('lti');
48+
49+
// launch action
50+
$module->on(Module::EVENT_LAUNCH, function (ToolProviderEvent $event){
51+
$tool = $event->sender;
52+
53+
// $userPk can be used for user identity
54+
$userPk = $tool->user->getRecordId();
55+
$isAdmin = $tool->user->isStaff() || $tool->user->isAdmin();
56+
57+
Yii::$app->session->set('isAdmin', $isAdmin);
58+
Yii::$app->session->set('userPk', $userPk);
59+
60+
$this->redirect(['site/index']);
61+
$tool->ok = true;
62+
});
63+
64+
$module->on(Module::EVENT_ERROR, function (ToolProviderEvent $event){
65+
Yii::error($event->sender->reason);
66+
});
67+
68+
return $module->handleRequest();
69+
}
5270
}
53-
```
71+
```

0 commit comments

Comments
 (0)