Cake\Network\Response::statusCode PHP Method

statusCode() public method

Sets the HTTP status code to be sent if $code is null the current code is returned
public statusCode ( integer | null $code = null ) : integer
$code integer | null the HTTP status code
return integer Current status code
    public function statusCode($code = null)
    {
        if ($code === null) {
            return $this->_status;
        }
        if (!isset($this->_statusCodes[$code])) {
            throw new InvalidArgumentException('Unknown status code');
        }
        return $this->_status = $code;
    }

Usage Example

Example #1
6
 public function beforeDispatch(Event $event)
 {
     $event->stopPropagation();
     $response = new Response(['body' => $this->config('message')]);
     $response->httpCodes([429 => 'Too Many Requests']);
     $response->statusCode(429);
     return $response;
 }
All Usage Examples Of Cake\Network\Response::statusCode