Framework PHP June 18, 2009

RedBean - the simplest (php) ORM in the world

I’ve used ActiveRecord and similar ORMs in a variety of languages, but I have never seen a framework as elegant as Gabor de Mooij’s RedBean. It not only makes manipulating and reading records from a database easy, it makes new changes to the database completely invisible.

RedBean’s Home Page

The real innovation was to allow the database to run in development mode, during which it alters the database any time your model structure changes. It generates the classes for you, so you don’t even have to write the actual models.

R::gen("BlogPost");

$post = new BlogPost();
$post->title = "Title";
$post->description = "description";
$post->save();

This will generate a blogpost table, and save your record for you, without having to run any migrations or anything. We’ve been using RedBean with ZendAMF on our projects and I feel very productive. Here is a more complete example.

<?php

require_once('libs/redbean/oodb.php');

R::gen("BlogPost","Comment");

$post = new BlogPost();
$post->title = "New Blog Title";
$post->description = "This is a sweet message and stuff";

$comment = new Comment();
$comment->user = "sean";
$comment->message = "I think this post is great";

$post->add($comment);

// we're just loading the 1st on the db, but you could
// find a particular one if you wanted. 
$currentPost = new BlogPost(1);  
$comments = $currentPost->getRelatedComment();

// Print them out in a view

Hello world

sdfgdfgdfgdfg

rtert

Just found this myself. I had started using Propel, largely because it seemed simpler than Doctrine.

I got frustrated with the amount of config files, and the semi-manual effort to reverse engineer my existing schema.

So, even apart from the unique 'dev mode', it's a winner. No config files, and no overly verbose getters/setters.

Very, very cool.

Should have been easier to find though. Searches for "php orm" should place it higher...I suppose word of mouth will get around soon enough.

Your comment was added successfully
Your comment could not be added

Leave a comment