FOSRestBundle:我看不到我的新路线
FOSRestBundle : I can't see my new route
我创建了一个扩展 FOSRestController 的新控制器 (testController)。当我 运行 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
我忘记了什么?
非常感谢!
我终于找到了答案...很简单,但我没看到!方法名称:
=> getTestAction
我创建了一个扩展 FOSRestController 的新控制器 (testController)。当我 运行 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
我忘记了什么?
非常感谢!
我终于找到了答案...很简单,但我没看到!方法名称:
=> getTestAction