【问题标题】:FOSRestBundle - No Route FoundFOSRestBundle - 未找到路线
【发布时间】:2015-04-24 07:05:33
【问题描述】:

我正在尝试使用 FOSRestBundle 在 Symfony 2.3 中创建一个 Rest Api。 我已按照此处的说明进行操作 http://obtao.com/blog/2013/05/create-rest-api-in-a-symfony-application/

我可以包含 route_rest.xml DocumentRestController.php 的内容是

namespace Demo\ListBundle\Controller;

use FOS\RestBundle\Controller\Annotations\View; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Security\Core\Exception\AccessDeniedException;


class DocumentRestController extends Controller {

    // "get_document"     [GET] /document/id
    public function getDocumentAction($id)
    {
        $document = $this->getDoctrine()->getRepository('ListBundle:Document')->find($id);
        if(!is_object($document)){
          throw $this->createNotFoundException();
        }
        return $document;   } }

我在路由调试中得到了这个

api_v1_get_document                  GET         ANY    ANY  /api/v1/documents/{id}.{_format}

但是当我访问该页面时,我发现找不到路线。

谢谢

【问题讨论】:

  • 如果找不到文档,您的代码将抛出 NotFoundException。你确定不是这样吗?
  • 命令console router:debug怎么说?
  • 您可以发布您尝试访问此的网址吗?
  • 控制台路由器:已附上调试

标签: php symfony fosrestbundle


【解决方案1】:

谢谢你们, 我终于弄明白了。从

复制粘贴时,我在 URI 中添加了一个额外的斜杠
php app/console router:debug | grep api

这是一个愚蠢的错误,我花了很长时间才弄明白。

【讨论】:

    猜你喜欢
    • 2014-06-06
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 2016-05-16
    • 1970-01-01
    • 2013-03-14
    • 2014-03-20
    相关资源
    最近更新 更多