Welcome Guest, Not a member yet? Register   Sign In
RedBean ORM
#9

[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
Code:
$this->ci =& get_instance();

// Include database configuration
include(APPPATH.'/config/database.php');

// Include required files
include(APPPATH.'/thirdparty/redbean/redbean.inc.php');

// 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:
Code:
$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


Messages In This Thread
RedBean ORM - by El Forum - 11-02-2009, 09:14 AM
RedBean ORM - by El Forum - 11-02-2009, 09:50 AM
RedBean ORM - by El Forum - 11-02-2009, 09:53 AM
RedBean ORM - by El Forum - 11-02-2009, 10:12 AM
RedBean ORM - by El Forum - 11-02-2009, 02:23 PM
RedBean ORM - by El Forum - 11-02-2009, 10:27 PM
RedBean ORM - by El Forum - 11-03-2009, 03:50 AM
RedBean ORM - by El Forum - 11-09-2009, 05:46 AM
RedBean ORM - by El Forum - 11-16-2009, 04:39 AM
RedBean ORM - by El Forum - 03-29-2010, 11:40 PM
RedBean ORM - by El Forum - 01-08-2011, 12:20 PM
RedBean ORM - by El Forum - 02-23-2012, 06:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB