【发布时间】: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