Picora™
Open Source PHP Micro Framework
The new release is out, and this page will be out of date until I get a chance to update it. Please report any bugs or problems to the forums! Thanks for your patience - Ryan
Introduction
Picora is a minimalist web framework that provides a way to organize your code by mapping URLs directly to class methods, and allows you to easily separate your business logic from your display logic.
Picora only intends to solve these very basic problems, no more and no less. Because it focuses on only solving these problems and these problems alone, it is extremely small, extremely fast, completely documented and has a small, easy to understand API. It's also namespaced and fits in one file. Picora requires PHP 5.0+ (5.2 recommended) and Apache 1.3+
Target Audience
This framework is mainly targeted at folks who have gotten used the MVC method of doing things through Rails or other frameworks, and who still use PHP for smaller projects.
A Sample Application
Below is an abbreviated example of a Blog application built with Picora. Four sample applications, including a working blog, are included in the download.
.htaccess
This set of rules for Apache serves out any file or folder that exists normally, and routes all other requests to index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
index.php
Picora is included and initialized, then two urls are mapped to the BlogController class. Finally, we tell the dispatcher where we are running it from, what URL the application lives at, and what page was requested.
require_once('../picora.php');
PicoraDispatcher::addRoute(array(
'/' => array('Blog','index'),
'/posts/:id' => array('Blog','post')
);
PicoraDispatcher::dispatch(dirname(__FILE__),'http://localhost/my_blog/',$_GET['route']);
controllers/BlogController.php
The BlogController renders an index.php view with a list of all posts, or the individual post that was requested. Each key passed into the render method becomes available as a local variable in the view file.
Note that the model() calls use a PHP ActiveRecord implementation which is not part of Picora, substitute with your own database logic for the time being.
class BlogController extends PicoraController {
public function index(){
return self::render('views/index.php',array(
'posts' => PicoraActiveRecord::findAll('Post')
));
}
public function post($id){
$post = PicoraActiveRecord::find('Post',$id);
if(!$post)
return false;
return self::render('views/post.php',array(
'post' => $post
));
}
}
views/post.php
View files are native PHP. The BlogController post() method renders this file and the post that was found by the BlogController is available as a local variable.
<h2><?php print $post->name;?></h2>
<p><?php print $post->body;?></p>