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 岁月祝福语简短10字
12 鸡年祝福语简短8字
13 母亲祝福语简短微信
14 妈妈生日祝福语简短优美
15 元旦祝福语简短给女友
16 女士祝福语幽默简短英语
17 雷州人结婚祝福语简短
18 亲人喜得贵子祝福语简短