在SYMFONY中添加特定的状态代码

在SYMFONY中添加特定的状态代码,symfony,Symfony,我将为我的应用程序symfony添加一个状态代码的特定方法。不是返回带有500个内部服务器错误的以下结果 Status Code: 500 Internal Server Error Connection: close Content-Length: 0 Content-Type: text/html Date: Tue, 08 Sep 2015 07:48:24 GMT Server: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16 X-Power

我将为我的应用程序symfony添加一个状态代码的特定方法。不是返回带有500个内部服务器错误的以下结果

Status Code: 500 Internal Server Error
Connection: close
Content-Length: 0
Content-Type: text/html
Date: Tue, 08 Sep 2015 07:48:24 GMT
Server: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
X-Powered-By: PHP/5.4.16
我想要一个新的状态码,比如

状态代码:900用户已注册

在symfony有可能吗?怎么做? 理论上说谢谢,是的,你可以。允许您传递状态代码。但是,此状态代码由HTTP协议定义(例如,请参阅)


对于错误消息,使用响应体(JSON、纯文本、html等)肯定要好得多。

Symfony提供了一个响应类:HTTP响应消息的简单PHP表示。这允许应用程序使用面向对象的接口来构造需要返回给客户机的响应。 因此,在控制器中,您可以按如下方式设置响应:

use Symfony\Component\HttpFoundation\Response;
.
.
.
$response = new Response();
$response->headers->set('Content-Type', 'text/html');
$response->setStatusCode(900);
$response->send();