karinto/karinto

a minimal web application framework

dev-master / 1.0.x-dev 2012-10-19 03:04 UTC

This package is not auto-updated.

Last update: 2024-04-13 13:09:37 UTC


README

Karinto is a minimal application framework for PHP 5.3 or later inspired by Silex based on Lune.

Required

  • PHP 5.3 or later
  • mbstring

Optional

You can use Twig as a template engine instead of using plain PHP templates.

Usage

/index.php

<?php
require_once 'Karinto.php';

use Karinto\Application;
use Karinto\Request;

$app = new Application();
$app->templateDir = 'templates';

// if using Twig
// $app->useTwig(array('cache' => 'cache'));

$app->error(function($code, \Exception $e = null) use ($app) {
    switch ($code) {
    case 404:
        $app->render('error_404.php');
        break;
    default:
        $app->render('error_general.php');
        break;
    }
});

$app->get('/', function(Request $req) use ($app) {
    $app->render('default.php');
});

$app->get('/foo', function(Request $req) use ($app) {
    $app['name'] = $req->param('name');
    $app->render('foo.php');
});

$app->get('/bar', function(Request $req) use ($app) {
    $session = $app->session();
    $session['name'] = $req->param('name');
    $app->redirect('/baz');
});

$app->run();

/templates/foo.php

<html>
<body>
<p><?php echo h($name); ?></p>
</body>
</html>

Please access "/index.php/foo?name=bar"

License

This code is free to use under the terms of the New BSD License.

With Composer

If using Composer as a dependency management tool, you can bring Karinto in your environment easily with settings below.

{
  "minimum-stability": "dev",
  "require": {
    "karinto/karinto": "1.0.*"
  }
}

Using Twig with Karinto, you should set as the same below:

{
  "minimum-stability": "dev",
  "require": {
    "karinto/karinto": "1.0.*",
    "twig/twig": "1.*"
  }
}