Symfony2路由错误找不到" GET / query"

时间:2015-06-01 22:08:34

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

我在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,

    ));

我的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

1 个答案:

答案 0 :(得分:0)

我想也许这是一条保留的路线或其他东西,不过我也在symfony 2.3上,这个快速测试工作正常:

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

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

相关问题