CodeIgniter Forums
RedBean ORM - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: RedBean ORM (/showthread.php?tid=24179)

Pages: 1 2

RedBean ORM - El Forum - 11-02-2009

[eluser]Boris Strahija[/eluser]
I'm just curious if anyone has successfully integrated RedBean ORM to work with CodeIgniter. It looks really simple and easy to use.

RedBean ORM - El Forum - 11-02-2009

It seems really, really cool, actually - but from a brief look I don't see why you'd really need to integrate it. It seems you just pop it in, include it, and use it as-is without modification.

RedBean ORM - El Forum - 11-02-2009

[eluser]Boris Strahija[/eluser]
Hm, I don't think it's that simple if I want to use the same configuration as the CI db class, and I want to use the $this->load->model() method.
Correct me if I'm wrong, but I think I need to build a hook or a MY_Model class.

RedBean ORM - El Forum - 11-02-2009

OIC, yes indeed not quite that simple. I'd start with getting it working the quick and dirty way, then working towards it just working. I believe you'd load it as a library first to get it using CI configuration (probably need a wrapper) then I think you are right about the MY_Model class.

Personal preference admittedly, but I rather like not having to use model loading to access database functions in DMZ, so I would think the short simple syntax offered by RedBeans would best to be preserved. $this->load->model('blog') seems inferior to $b = new Blog() - but again, personal preference.

RedBean ORM - El Forum - 11-02-2009

[eluser]Boris Strahija[/eluser]
I was trying to do it myself, and I'm still trying some things out. I just tought that maybe somebody already did this.
I will definitely try to integrate it myself, and if it's good enogh maybe I'll share the code Wink

RedBean ORM - El Forum - 11-02-2009

ORM should not be used as a model, they are totally separate things. A model can encapsulate ORM if required.

Of course the biggest mistake is to perform business logic in the controller using ORM objects directly, instead of passing to a model.

RedBean ORM - El Forum - 11-03-2009

[eluser]Boris Strahija[/eluser]
Yes, you're absolutely right. It's a completely separate thing.

But I would need a model to create an object, of let's say Post(). The best way would be to use autoloading I suppose.
I think it would be something similar to the Doctrine integration.

RedBean ORM - El Forum - 11-09-2009

You should indeed not use RedBean beans instead of Models. But you can use the beans inside your models. On my website I offer various ways to integrate beans in models. Depending on your architectural preferences you can pick the solution that appeals to you.

I am not sure how easy it is to integrate CI and RedBean. The Kohana folks seem to be discussing the same right now.

RedBean ORM - El Forum - 11-16-2009

[eluser]Boris Strahija[/eluser]
I had some time today and I got RedBean working with CI. It was actually very simple. I'm sure there's a better way but this one works for me just fine. So here's my sollution if anyone is interested:

1. I put all the RedBean files into /app/thirdparty/redbean/
2. Create a library (/app/libraries/redbean.php), and put this code into the constructor
$this->ci =& get_instance();

// Include database configuration

// Include required files

// Database data
$hostname     = $db[$active_group]['hostname'];
$username     = $db[$active_group]['username'];
$password     = $db[$active_group]['password'];
$database     = $db[$active_group]['database'];

// Create RedBean instance
$toolbox = RedBean_Setup::kickstartDev('mysql:host='.$hostname.';dbname='.$database, $username, $password);
$this->ci->rb = $toolbox->getRedBean();

3. Then in your controller you can do stuff like this:
$post = $this->rb->dispense("post");
$post->title = 'My first post from CodeIgniter';
$post->body ='Lorem ipsum dolor sit amet, consectetur adipisicing elit....';
$post->created = time();
$id = $this->rb->store($post);

Ant that's it. Haven't tested it much but everything seems to work.
If someone has a better sollution just let me know Wink

RedBean ORM - El Forum - 03-29-2010

Thanks for the posts, Boris. Got me set up almost immediately.

I've been trying out just setting up a few ORMs in the past few days and have grown increasingly frustrated at the complexity - I wanted a simple, lightweight drop-in ORM.

RedBean works swell so far!