Slide 11
Slide 11 text
Controller の概要
11
namespace App\Controller;
final class ProductController extends AbstractController
{
#[Route(path: '/example', methods: ['GET'])]
public function example(): JsonResponse
{
return $this->json([
'message' => 'Hello, Symfony World!',
]);
}
}
#[Route] で Controller のメソッドと URL を
対応付け
path: URL のパスを指定
methods: HTTP メソッドを指定
API を呼び出された際に実
行
する処理を
Controller のメソッド内に記述