THttpResponse implements the mechanism for sending output to client users. To output a string to client, use {@link write()}. By default, the output is buffered until {@link flush()} is called or the application ends. The output in the buffer can also be cleaned by {@link clear()}. To disable output buffering, set BufferOutput property to false. To send cookies to client, use {@link getCookies()}. To redirect client browser to a new URL, use {@link redirect()}. To send a file to client, use {@link writeFile()}. By default, THttpResponse is registered with {@link TApplication} as the response module. It can be accessed via {@link TApplication::getResponse()}. THttpResponse may be configured in application configuration file as follows where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl} and {@link getBufferOutput BufferOutput} are optional properties of THttpResponse. THttpResponse sends charset header if either {@link setCharset() Charset} or {@link TGlobalization::setCharset() TGlobalization.Charset} is set. Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property. Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode} in your application, be sure to add theses informations. E.g : to make an http authentication : public function clickAuth ($sender, $param) { $response=$this->getResponse(); $response->setStatusCode(401); $response->appendHeader('WWW-Authenticate: Basic realm="Test"'); } This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This will force the browser to ask for a username and a password.
С версии: 3.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends Prado\TModule, implements Prado\IO\ITextWriter
Пример #1
0
 public function testWriteFile()
 {
     // Don't know how to test headers :(( ...
     throw new PHPUnit_Framework_IncompleteTestError();
     $response = new THttpResponse();
     $response->setBufferOutput(true);
     // Suppress warning with headers
     $response->writeFile(dirname(__FILE__) . '/data/aTarFile.md5', null, 'text/plain', array('Pragma: public', 'Expires: 0'));
     self::assertContains('4b1ecb0b243918a8bbfbb4515937be98  aTarFile.tar', ob_get_clean());
 }