Symfony';s createNotFoundException未返回404页

Symfony';s createNotFoundException未返回404页,symfony,http-status-code-404,Symfony,Http Status Code 404,我有一个Symfony操作,当查询返回NULL时,我试图返回404错误 我总是返回常规页面的模板和200HTTP返回代码 我已经检查过,错误日志显示createNotFoundException正在触发 我正在运行Symfony 2.7.1 你知道为什么这段代码没有返回404页面吗 <?php namespace Example\GroupBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controlle

我有一个Symfony操作,当查询返回NULL时,我试图返回404错误

我总是返回常规页面的模板和200HTTP返回代码

我已经检查过,错误日志显示createNotFoundException正在触发

我正在运行Symfony 2.7.1

你知道为什么这段代码没有返回404页面吗

<?php

namespace Example\GroupBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;

use Example\GroupBundle\Entity\Group;

/**
 * Class SupportGroupLandingController
 * @package Example\GroupBundle\Controller
 *
 * @Route("/group")
 */
class SupportGroupController extends Controller
{
    /**
     * @Route("/{name}", name="support_group_page")
     * @Method("GET")
     * @Template("ExampleGroupBundle::group_page.html.twig")
     *
     * @param $name
     * @return array
     */
    public function indexAction($name)
    {
        $repo = $this->getDoctrine()->getRepository('ExampleGroupBundle:Group');
        $group = $repo->findOneBy(array('name' => $name));

        if ($group === NULL) {
            error_log('group is null');

            return $this->createNotFoundException('Support Group does not exist');

            error_log('this should not be here');

        } else {
            error_log('group is not null: '.var_export($group, TRUE));
        }

        return array('group' => $group);
    }


}

您不需要返回
$this->createNotFoundException('支持组不存在')但是抛出它:

throw $this->createNotFoundException('Support Group does not exist');

您不需要返回
$this->createNotFoundException('支持组不存在')但是抛出它:

throw $this->createNotFoundException('Support Group does not exist');

谢谢简单的事情:-)谢谢!这么简单的事情:-)