FOSRestBundle:我看不到我的新路线了

时间:2017-06-20 09:35:29

标签: symfony fosrestbundle

我创建了一个新的控制器(testController),它扩展了FOSRestController。当我运行symfony命令“debug:router”时,我无法看到我在此控制器中创建的路径“/ test”。对于Postman,我有404错误......

我确定我忘记了什么,但我不知道是什么。这是我的代码:

testController.php

<?php

namespace Project\ApiBundle\Controller;

use FOS\RestBundle\Controller\Annotations;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Delete;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Put;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\RouteRedirectView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use JMS\Serializer\SerializationContext; 

/**
 * Class testController.
 */
class testController extends FOSRestController
{
    /**
     * List .
     * @ApiDoc(
     *   resource = true,
     *   statusCodes = {
     *     200 = "Returned when successful"
     *   }
     * )
     *
     * @Rest\View()
     * @Get("/test")
     *
     * @param Request $request the request object
     *
     * @return array
     */
    public function getTest(Request $request)
    {
       return "hello world";

    }
}

而且,这是我的routing.yml文件:

api_test:
  type: rest
  resource:     Project\ApiBundle\Controller\TestController

我忘记了什么?

非常感谢!

1 个答案:

答案 0 :(得分:1)

我终于找到了答案......这么简单,但我没有看到它!方法名称:

=&GT; getTest 操作