symfony2 返回404响应
示例
当在服务器上找不到资源时,将返回404响应。在Symfony中,可以通过引发NotFoundHttpException异常来创建此状态。为了避免use在控制器内部添加多余的语句,请使用类createNotFoundException()提供的Controller
<?php
namespace Bundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class TestController extends Controller
{
/**
* @Route("/{id}", name="test")
* Recommended to avoid template() as it has a lot of background processing.
* Query database for 'test' record with 'id' using param converters.
*/
public function testAction(Test $test)
{
if (!$test) {
throw $this->createNotFoundException('Test record not found.');
}
return $this->render('::Test/test.html.twig', array('test' => $test));
}
}
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语