Prado\Web\THttpResponse::setStatusCode PHP Метод

setStatusCode() публичный Метод

The code and its reason will be sent to client using the currently requested http protocol version (see {@link THttpRequest::getHttpProtocolVersion}) Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1
public setStatusCode ( $status, $reason = null )
    public function setStatusCode($status, $reason = null)
    {
        if ($this->_httpHeaderSent) {
            throw new \Exception('Unable to alter response as HTTP header already sent');
        }
        $status = TPropertyValue::ensureInteger($status);
        if (isset(self::$HTTP_STATUS_CODES[$status])) {
            $this->_reason = self::$HTTP_STATUS_CODES[$status];
        } else {
            if ($reason === null || $reason === '') {
                throw new TInvalidDataValueException("response_status_reason_missing");
            }
            $reason = TPropertyValue::ensureString($reason);
            if (strpos($reason, "\r") != false || strpos($reason, "\n") != false) {
                throw new TInvalidDataValueException("response_status_reason_barchars");
            }
            $this->_reason = $reason;
        }
        $this->_status = $status;
    }

Usage Example

Пример #1
0
 public function testSetStatusCode()
 {
     $response = new THttpResponse();
     $response->init(null);
     $response->setStatusCode(401);
     self::assertEquals(401, $response->getStatusCode());
     $response->setStatusCode(200);
     self::assertEquals(200, $response->getStatusCode());
 }