From ea17c0d844fcf76c1a4b19d90fc6fc4df6987909 Mon Sep 17 00:00:00 2001 From: Julian Paolo Dayag Date: Wed, 20 Jul 2016 13:49:17 +0800 Subject: [PATCH 1/2] add enable events dispatcher support --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 48e2261..9090b4b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,31 @@ $resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci); Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); ``` +To enable events dispatcher support: + +```php +// use our mock PDO class if PDO is not enabled on this server +if (!class_exists('PDO')) { + class_alias('Illuminate\CodeIgniter\FakePDO', 'PDO'); +} + +// pass all Laravel database queries through to CodeIgniter +$ci = get_instance(); +$resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci); + +// create a new event dispatcher instance +$event_dispatcher = new Illuminate\Events\Dispatcher(); +//create a new database manager instance +$database_manager = new Illuminate\Database\Capsule\Manager(); +// attach the evebt dispatcher instance to the manager instance +$database_manager->setEventDispatcher($event_dispatcher); +// attach the event dispatcher to the eloquent +$database_manager->bootEloquent(); + +Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); +``` + + ## License [MIT License](https://github.com/expressodev/laravel-codeigniter-db/blob/master/LICENSE) From 1aeb0e2dbd40b8b76ee0a5922f7753965129de9c Mon Sep 17 00:00:00 2001 From: Julian Paolo Dayag Date: Wed, 20 Jul 2016 13:58:44 +0800 Subject: [PATCH 2/2] fix eloquent transaction not working created a new pdo instance and assigned it to the pdo class variable which is used in the transaction methods. --- src/CodeIgniterConnection.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CodeIgniterConnection.php b/src/CodeIgniterConnection.php index 53fc6c2..63eb86d 100644 --- a/src/CodeIgniterConnection.php +++ b/src/CodeIgniterConnection.php @@ -21,6 +21,13 @@ public function __construct($ci) $this->tablePrefix = $this->ci->db->dbprefix; $this->useDefaultQueryGrammar(); $this->useDefaultPostProcessor(); + try { + $this->pdo = new PDO("{$this->ci->db->dbdriver}:host={$this->ci->db->hostname};dbname={$this->ci->db->database};charset={$this->ci->db->char_set}", $this->ci->db->username, $this->ci->db->password); + } catch(Exception $e) { + if ($this->ci->db->dbdriver == "mysqli") { + $this->pdo = new PDO("mysql:host={$this->ci->db->hostname};dbname={$this->ci->db->database};charset={$this->ci->db->char_set}", $this->ci->db->username, $this->ci->db->password); + } + } } /** @@ -74,7 +81,7 @@ protected function getDefaultPostProcessor() */ public function getPdo() { - throw new \BadMethodCallException('PDO is not supported by CodeIgniter database driver'); + return $this->pdo; } /**