找不到 "GET /demo/koco/create" 的路由:404 未找到 - NotFoundHttpException

No route found for "GET /demo/koco/create" : 404 Not Found - NotFoundHttpException

为什么我收到路线错误? CRUD 操作的其他 APIs 工作正常。 我为我的新 API 添加了一个新的控制器代码,但出现了路由错误。 可能是什么错误?

虽然我已经在routing.yml

中写好了路线
creat:
  path: /create
  defaults: { _controller: AcmeDemoBundle:DemoController:create }
  methods: [GET]

Products:
  path: /recentProducts/{id}
  defaults: { _controller: AcmeDemoBundle:DemoController:recentProducts }
  methods: [GET]

Update:
  path: /updateProduct/{id}
  defaults: { _controller: AcmeDemoBundle:DemoController:update }
  methods: [POST]

Delete:
  path: /deleteProduct/{id}
  defaults: { _controller: AcmeDemoBundle:DemoController:delete }
  methods: [DELETE]

referenceCreation:
  path: /koco/create
  defaults: { _controller: AcmeDemoBundle:DemoController:createReference }
  methods: [GET]

我的api是 http://localhost/koco1/web/app_dev.php/demo/koco/create

我的控制器是

/**
     * @Route("/koco/create", name="referenceCreation")
     * @Template()
     */
    public function createReferenceAction()
    {

        $organization = new Organization();
        $organization->setName('Sensio Lab');

        $user = new User();
        $user->setName("Jonathan H. Wage");
        $user->setOrganization($organization);


        $dm = $this->get('doctrine_mongodb')->getManager();
        $dm->persist($organization);
        $dm->persist($user);
        $dm->flush();

        return new Response('Created product id ');

        // $response = new Response('Hello Huzaifa ');
        // return $response;
    }

这里有什么问题? 请告诉我。 谢谢

您的路由已关闭。 您还通过 yaml 和注释创建路由。应该坚持一个。

服务器设置也看起来不对,http://localhost/koco1/web/app_dev.php/demo/koco/create应该更像http://localhost/koco1/web/koco/create,你可以试试运行 php 服务器。转到 /public 和 运行 php -S localhost:8000 你可以在这里阅读更多内容:https://www.php.net/manual/en/features.commandline.webserver.php

或 symfony cli 服务器https://symfony.com/download

你的路由不匹配/demo/koco/create不等于/koco/create,你应该首先设置正确,然后调试起来会更容易。