Skip to content

Instantly share code, notes, and snippets.

@chrisgaraffa
Last active Aug 5, 2016
Embed
What would you like to do?
Using Eloquent ORM and EventDispatcher with CodeIgniter
/*
* Install the following via composer:
* "illuminate/database": "^5.2"
* "illuminate/events": "^5.2"
* Add require_once('./vendor/autoload.php'); to config/autoload.php
* Add this to the end of your database.php file, or your config/ENVIRONMENT/database.php file as needed:
*/
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => $db[ENVIRONMENT]['hostname'],
'database' => $db[ENVIRONMENT]['database'],
'username' => $db[ENVIRONMENT]['username'],
'password' => $db[ENVIRONMENT]['password'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => $db[ENVIRONMENT]['dbprefix']
));
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
$capsule->bootEloquent();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment