LoginSignup
0
1

More than 1 year has passed since last update.

EC-CUBE4 特定のルート除外して特定のルートにプレフィックスをつける方法

Posted at
app/config/eccube/routes.yaml
controllers:
    resource: ../../src/Eccube/Controller/
    type: annotation
customize_controllers:
-    resource: ../../app/Customize/Controller/
+    resource: ../../app/Customize/Controller/**/**
    type: annotation
+    exclude: '../../app/Customize/Controller/Api/'
+ customize_api_controllers:
+     resource: ../../app/Customize/Controller/Api
+     type: annotation
+     prefix: /v1
+     name_prefix: v1_api_

exclude を記述しなかった場合、customize_controllers の定義で1つ、customize_api_controllers の定義で一つ(プレフィックス付き)の2つが、ルーターに登録されてしまう。

例えば、以下のようなルートを追加した場合。

<?php

declare(strict_types=1);

namespace Customize\Controller\Api;

use Eccube\Controller\AbstractController;
use Eccube\Entity\Member;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

class MeController extends AbstractController
{
    /**
     * @Route("/me", name="me", methods={"GET"}, condition="request.headers.get('Accept') === 'application/json'")
     */
    public function me(): JsonResponse
    {
        $user = $this->getUser();

        if ($user === null) {
            return $this->json([
                'logged_in' => false,
                'member_id' => null,
            ]);
        }

        assert($user instanceof Member);

        return $this->json([
            'logged_in' => true,
            'member_id' => $user->getId(),
        ]);
    }
}

先ほどの exclude の記述がない場合は、下記画像の左側のように、2個のルートが登録されます。
exclude の記述がある場合は、下記画像の側のようになります。

スクリーンショット 2022-03-29 11.03.23.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1