【问题标题】:Symfony2 routing error No route found for "GET /query"Symfony2 路由错误找不到“GET /query”的路由
【发布时间】:2015-08-15 12:58:37
【问题描述】:

我在 Symfony2 v2.3 中创建新路由时遇到问题。我收到错误消息

No route found for "GET /query"
404 Not Found - NotFoundHttpException
1 linked Exception: ResourceNotFoundException »

我已经搜索了解决方案,但没有一个有效...我什至崩溃了一个尝试 appDevUrlGenerator.php 和 appDevUrlMatcher.php 的服务器。

所以,这是我的 DefaultController 中的部分代码:

public function queryAction(Request $request)
{
    $repository=$this->getDoctrine()->getRepository('TestFirstBundle:UserTicket');


    $lists = $repository->findBystatus('Open');


    if (!$lists) {
        throw $this->createNotFoundException(
            'No forms found '
        );
    }

    return $this->render('TestFirstBundle:Default:query.html.twig', array(
        'lists' => $lists,

    ));

我在 bundle 中的 routing.yml:

test_First_homepage:
path:     /dipl
defaults: { _controller: TestFirstBundle:Default:index }


test_First_submit:
path:     /subm
defaults: { _controller: TestFirstBundle:Default:submit }

test_First_query:
path:     /query
defaults: { _controller: TestFirstBundle:Default:query }

和 app/config/routing.yml(我在 app/config/routing_dev.yml 中放了同样的东西)

test_first:
resource: "@TestFirstBundle/Resources/config/routing.yml"
prefix:   /

我将添加 /dipl 和 /subm 路由完美运行,它们连接到我放置表单的 indexAction 和 submitAction(提交表单后重定向)。此外,如果我注释掉我真正的 indexAction 并将 queryAction 重命名为 indexAction,它可以在 /dipl url 上完美运行,并且完全正确地执行 queryAction 应该做的事情。所以我猜测 queryAction 和 /query url 之间的连接存在问题。但是当我运行时

   php app/console router:match /query 

我猜对了:

[router] Route "test_First_query"
Name         test_First_query
Path         /query
Host         ANY
Scheme       ANY
Method       ANY
Class        Symfony\Component\Routing\Route
Defaults     _controller:           Test\FirstBundle\Controller\DefaultController::queryAction
Requirements NO CUSTOM
Options      compiler_class: Symfony\Component\Routing\RouteCompiler
Path-Regex   #^/query$#s

【问题讨论】:

    标签: php symfony routes http-status-code-404


    【解决方案1】:

    我想这可能是一条保留路线之类的,但是我也在 symfony 2.3 上,这个快速测试运行良好:

    /**
     * @Route("/query", name="query")
     */
    public function queryAction()
    {
        return new Response('query');
    }
    

    我得到回复 OK。所以不是这样。可能是您在 Symfony2 之外的 /query 下配置了某种别名或资源(可能在您的 HTTP 服务器中?)以某种方式干扰了此路由?

    【讨论】:

    • 我尝试为该操作/路由/url 使用随机名称,无论我如何命名它都是一样的。另外,我正在运行 localhost,这是我的第一个项目
    猜你喜欢
    • 1970-01-01
    • 2016-03-27
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 2013-07-29
    • 2017-09-25
    相关资源
    最近更新 更多