Caw - a small lightweight response system for PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Caw - a small lightweight response system for PHP


###Install with Composer

If you're using Composer to manage dependencies, you can add Caw with it.

    "require": {
        "corvum/caw": "dev-master"




###Basic Usage

$caw = new \Corvum\Caw([
    'viewsDir' => dirname (__FILE__).'/views/', //Directory for views
    'view' => 'index' //Default View
$caw->siteTitle = 'Corvum';
$caw->siteLead = 'Easy to Use PHP Tools';
$caw->setView('index');  //index.php in the views directory

###API / JSON Usage

$caw = new \Corvum\Caw([
    'responseType' => 'JSON'
$caw->siteTitle = 'Corvum';
$caw->siteLead = 'Easy to Use PHP Tools';


$caw = new \Corvum\Caw();
$caw->siteTitle = 'Corvum';
$caw->siteLead = 'Easy to Use PHP Tools';

####Enable Cors

To be able to use this as a true API from other domains, you will need to enable CORS.

$caw = new \Corvum\Caw([
    'responseType' => 'JSON',
    'enableCORS' => true



###Setting Cookies

Setting Cookies is done just as you normally with setcookie(). $time defaults to '+1 day' but accepts anything strtotime() does.

$caw->setCookie($name, $value, $time);

The reason to use Caw's setCookie method is to ensure that everything is sent to the server in the proper order for the HTTP Response. If you ensure that you use Caw as the only sending data down, your headers, cookies and content will always work. That is a reason I created Caw, to keep from accidentally starting to send something back, and cookies or headers didn't work because they weren't in the correct order

###Setting Headers

$caw->setHeader('Content-Type', 'application/json');

###HTTP Status Codes

$caw->setStatusCode('404','Not Found');

###Render Data

Sometimes it's useful to just render the data and return that back to the application. To do that with Caw, you just need to use render() instead of respond()



Stop allows you to exit your application while still sending down what view/data you have already set. This ensures that you can exit either gracefully (by setting a default view) or send empty responses with status code (no view/data)