@@ -65,16 +65,17 @@ class ExampleController extends \yii\web\Controller {
6565 return "Params received: \$foo = $foo.";
6666 }
6767
68- // Passing params as Yii request body params must be handy too, when we need to do a bulk
68+ // Passing params as Yii request body params must be handy too, when we need to do a massive
6969 // attribute assignment for example.
7070 public function actionTryWithBodyParams() {
71- $output = "Params received: \n";
71+ $output = "Params received: ";
72+ $output_chunks = array();
7273 foreach (\Yii::$app->request->getBodyParams() as $name => $value) {
73- $output . = "$name = $value\n";
74+ $output_chunks[] = "$name = $value\n";
7475 }
75- return $output;
76+ return $output . implode(', ', $output_chunks) . '.' ;
7677 }
77-
78+
7879}
7980```
8081
@@ -87,10 +88,8 @@ Now this is how calls and responses will look like:
8788<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar.", "id": 2}
8889
8990// Using alternative entry point:
90- -> {"jsonrpc": "2.0", "method": "api1.example.try-with-body-params", "params": {"foo": "bar"}, "id": 2}
91- <- {"jsonrpc": "2.0", "result": "Params received:
92- $foo = bar.
93- ", "id": 2}
91+ -> {"jsonrpc": "2.0", "method": "api1.example.try-with-body-params", "params": {"foo": "bar", "foo1": "bar1"}, "id": 2}
92+ <- {"jsonrpc": "2.0", "result": "Params received: $foo = bar, $foo1 = bar1.", "id": 2}
9493
9594-> {"jsonrpc": "2.0", "method": "api1.example.garbage", "id": 3}
9695<- {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": 3}
0 commit comments