💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Class Phalcon\\Http\\Response # Class **Phalcon\\Http\\Response** *implements*[*Phalcon\\Http\\ResponseInterface*](#), `Phalcon\Di\InjectionAwareInterface` Part of the HTTP cycle is return responses to the clients. Phalcon\\HTTP\\Response is the Phalcon component responsible to achieve this task. HTTP responses are usually composed by headers and body. ``` <pre class="calibre14">``` <?php $response = new \Phalcon\Http\Response(); $response->setStatusCode(200, "OK"); $response->setContent("<html><body>Hello</body></html>"); $response->send(); ``` ``` ### Methods public **\_\_construct** (\[*string* $content\], \[*int* $code\], \[*string* $status\]) Phalcon\\Http\\Response constructor public **setDI** (*unknown* $dependencyInjector) Sets the dependency injector public **getDI** () Returns the internal dependency injector public **setStatusCode** (*unknown* $code, \[*unknown* $message\]) Sets the HTTP response code ``` <pre class="calibre14">``` <?php $response->setStatusCode(404, "Not Found"); ``` ``` public **getStatusCode** () Returns the status code ``` <pre class="calibre14">``` <?php print_r($response->getStatusCode()); ``` ``` public **setHeaders** (*unknown* $headers) Sets a headers bag for the response externally public **getHeaders** () Returns headers set by the user public **setCookies** (*unknown* $cookies) Sets a cookies bag for the response externally public [*Phalcon\\Http\\Response\\CookiesInterface*](#)**getCookies** () Returns coookies set by the user public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**setHeader** (*string* $name, *string* $value) Overwrites a header in the response ``` <pre class="calibre14">``` <?php $response->setHeader("Content-Type", "text/plain"); ``` ``` public **setRawHeader** (*unknown* $header) Send a raw header to the response ``` <pre class="calibre14">``` <?php $response->setRawHeader("HTTP/1.1 404 Not Found"); ``` ``` public **resetHeaders** () Resets all the stablished headers public **setExpires** (*unknown* $datetime) Sets a Expires header to use HTTP cache ``` <pre class="calibre14">``` <?php $this->response->setExpires(new DateTime()); ``` ``` public **setNotModified** () Sends a Not-Modified response public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**setContentType** (*string* $contentType, \[*string* $charset\]) Sets the response content-type mime, optionally the charset ``` <pre class="calibre14">``` <?php $response->setContentType('application/pdf'); $response->setContentType('text/plain', 'UTF-8'); ``` ``` public **setEtag** (*unknown* $etag) Set a custom ETag ``` <pre class="calibre14">``` <?php $response->setEtag(md5(time())); ``` ``` public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**redirect** (\[*string|array* $location\], \[*boolean* $externalRedirect\], \[*int* $statusCode\]) Redirect by HTTP to another action or URL ``` <pre class="calibre14">``` <?php //Using a string redirect (internal/external) $response->redirect("posts/index"); $response->redirect("http://en.wikipedia.org", true); $response->redirect("http://www.example.com/new-location", true, 301); //Making a redirection based on a named route $response->redirect(array( "for" => "index-lang", "lang" => "jp", "controller" => "index" )); ``` ``` public **setContent** (*unknown* $content) Sets HTTP response body ``` <pre class="calibre14">``` <?php response->setContent("<h1>Hello!</h1>"); ``` ``` public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**setJsonContent** (*mixed* $content, \[*int* $jsonOptions\], \[*unknown* $depth\]) Sets HTTP response body. The parameter is automatically converted to JSON ``` <pre class="calibre14">``` <?php $response->setJsonContent(array("status" => "OK")); ``` ``` public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**appendContent** (*string* $content) Appends a string to the HTTP response body public **getContent** () Gets the HTTP response body public **isSent** () Check if the response is already sent public **sendHeaders** () Sends headers to the client public **sendCookies** () Sends cookies to the client public **send** () Prints out HTTP response to the client public <a class="calibre6 pcalibre1" href="">*Phalcon\\Http\\Response*</a>**setFileToSend** (*string* $filePath, \[*string* $attachmentName\], \[*unknown* $attachment\]) Sets an attached file to be sent at the end of the request | - [索引](# "总目录") - [下一页](# "Class Phalcon\Http\Response\Cookies") | - [上一页](# "Class Phalcon\Http\Request\File") | - [API Indice](#) »