[英]Symfony2: Weird route not found error
So I have it defined as: 所以我将其定义为:
/**
* Class TemplateController
* @package TemplateManager\Bundle\DocumentGeneratorBundle\Controller\API
* @Route("/api/v1/templates")
*/
class TemplateController extends Controller
{
/**
* @Route("?available={id}")
* @Method({"GET"})
*/
public function findAllAction($id)
{
echo "Yu";
}
/**
* @Route("/{id}")
* @Method({"GET"})
* @param $id
* @param $template_name
* @return Response
*/
public function findAction($id)
{}
}
When accessing it as: http://localhost/api//v1/templates?available=1
it says no matching route found. 当以如下方式访问它时:
http://localhost/api//v1/templates?available=1
它表示找不到匹配的路由。 Where am I doing wrong? 我在哪里做错了? The other route works fine.
另一条路线工作正常。
Your base route for your controller is defined as @Route("/api/v1/templates")
, but you're only calling "/api/templates/*". 控制器的基本路由定义为
@Route("/api/v1/templates")
,但您仅调用“ / api / templates / *”。 You simply forgot the "/v1/" in there. 您只是忘记了其中的“ / v1 /”。
Try calling http://localhost/api/v1/templates?available={id}
. 尝试致电
http://localhost/api/v1/templates?available={id}
。
Please note: on the CLI you can always dump all registered routes for easier debugging. 请注意:在CLI上,您始终可以转储所有已注册的路由,以便于调试。 Just type:
只需输入:
$> app/console debug:router
# or bin/console if you're using Symfony3 and above
$> bin/console debug:router
Shouldn't it be 不是吗
http://localhost/api/template?available=1
instead of 代替
http://localhost/api/templates?available=1
check your controller class and word used in the URL. 检查您的控制器类和URL中使用的单词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.