You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Method is not translated to route as an URL. It should contain actual actual module name, controller and route splitted by dots. So if you have a following URL rule:
17
-
`'do-some-stuff' => 'api1/doer/stuff'`
18
-
your method string should not be `'do-some-stuff'`, but `'api1.doer.stuff'`. Remember that you are just remotely calling procedures, which in Yii2 terms are actions.
19
-
* Note that action is called internally which causes some restrictions on them. One of them is that called action has to approve verb which you use originally for making a JSON-RPC call (most probably it will be GET or POST).
20
16
21
-
## Examples
17
+
## Usage
22
18
Entry point:
23
19
```php
24
20
<?php
25
21
26
22
namespace app\controllers;
27
23
28
24
class JsonRpcController extends \georgique\yii2\json-rpc\Controller {
25
+
29
26
// Practically you don't need anything else in this controller,
30
27
// unless you want to customize entry point somehow.
28
+
31
29
}
32
30
```
33
31
@@ -36,13 +34,22 @@ Controller with target actions which we are going to call:
36
34
<?php
37
35
namespace app\modules\api1\controllers;
38
36
37
+
// There are some minor side-effects of this solutions, because original request is made to the
38
+
// entry point, not to the target controller and action. Be careful working with Request object,
39
+
// especially when working on access restriction to the target actions. For example, you want an
40
+
// action to be reached only with GET verb only, but you do POST request to the endpoint. In that
41
+
// case you will get Internal Error because access will be denied.
39
42
class ExampleController extends \yii\web\Controller {
40
43
41
-
44
+
// Note that URL patterns won't be used to resolve the method - this would not be resourse-wise.
45
+
// Method string should simply be [[module.]controller.]action where module and controller parts
46
+
// can be omitted, so default module and index controller will be used.
42
47
public function actionTry() {
43
48
return "You've got it!";
44
49
}
45
50
51
+
// Method params are directly translated into action arguments. Make sure your call matches action
0 commit comments