Skip to content

Instantly share code, notes, and snippets.

@chrisgaraffa
Last active August 5, 2016 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisgaraffa/ebffc6a4781fdf6ac95d479fe0aed292 to your computer and use it in GitHub Desktop.
Save chrisgaraffa/ebffc6a4781fdf6ac95d479fe0aed292 to your computer and use it in GitHub Desktop.
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