Skip to content

Commit 961710e

Browse files
committed
update pdo config、update routes
1 parent 62718fb commit 961710e

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

app/Controller/IndexController.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@
88
* @document https://doc.simps.io
99
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1010
*/
11-
1211
namespace App\Controller;
1312

1413
class IndexController
1514
{
1615
public function index($request, $response)
1716
{
18-
$response->end('Hello Simps.');
17+
$response->end(
18+
json_encode(
19+
[
20+
'method' => $request->server['request_method'],
21+
'message' => 'Hello Simps.',
22+
]
23+
)
24+
);
1925
}
2026

21-
public function test($request, $response, $data)
27+
public function hello($request, $response, $data)
2228
{
23-
$response->end(json_encode($data));
24-
}
29+
$name = $data['name'] ?? 'Simps';
2530

26-
public function favicon($request, $response)
27-
{
28-
$response->end('');
31+
$response->end(
32+
json_encode(
33+
[
34+
'method' => $request->server['request_method'],
35+
'message' => "Hello {$name}.",
36+
]
37+
)
38+
);
2939
}
3040
}

config/database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @document https://doc.simps.io
99
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1010
*/
11-
1211
return [
1312
'host' => 'localhost',
1413
'port' => 3306,
@@ -17,6 +16,7 @@
1716
'password' => 'root',
1817
'charset' => 'utf8mb4',
1918
'options' => [
19+
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
2020
],
21-
'size' => 64
21+
'size' => 64,
2222
];

config/routes.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
* @document https://doc.simps.io
99
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1010
*/
11-
1211
return [
1312
['GET', '/', '\App\Controller\IndexController@index'],
14-
['POST', '/', '\App\Controller\IndexController@index'],
15-
['GET', '/test/{id:\d+}', '\App\Controller\IndexController@test'],
16-
// ico应该使用enable_static_handler
17-
['GET', '/favicon.ico', '\App\Controller\IndexController@favicon'],
13+
['GET', '/hello[/{name}]', '\App\Controller\IndexController@hello'],
14+
['GET', '/favicon.ico', function ($request, $response) {
15+
$response->end('');
16+
}],
1817
];

0 commit comments

Comments
 (0)