Skip to content

Response

John Aldrich Bernardo edited this page Jan 28, 2018 · 3 revisions

set

Set response value.

<?php

$home = new \Calf\HTTP\Route('/', function($req, $res) {
        return $res->set('Hello World!');
    });

Hello World!

Setting array response...

<?php

$home = new \Calf\HTTP\Route('/', function($req, $res) {
        return $res->set(['message' => 'Hello World!']);
    });

{"message":"Hello World!"}

get

Get response value.

Parameters:

  • $raw:boolean - Get raw value
<?php

$home = new \Calf\HTTP\Route('/', function($req, $res) {
        $res->set(['message' => 'Hello World!']);

        return $res->get(true);
    });

array(1) { ["message"] => string(12) "Hello World!" }

setHeader

Set HTTP Header(s).

Parameters:

  • $headers:mixed - Header or headers to be set
$res->setHeader("Content-Disposition: attachment");

getHeaders :array

Return headers set in the response.

setCookie

Set cookie(s) in the response.

<?php

$home = new \Calf\HTTP\Route('/', function($req, $res) {
        $res->set(['message' => 'Hello World!']);
        $res->setCookie(['Hello'=>'World']);

        return $res->get(true);
    });

getCookies :array

Return cookies set in the response.

compress

Compress output (gzip).

render :void

Set response headers and cookies, and print response text.

Clone this wiki locally