laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.7k stars 11.06k forks source link

Using Illuminate/database with CodeIgniter #3801

Closed ehsanquddusi closed 10 years ago

ehsanquddusi commented 10 years ago

I am trying to use the package with my CodeIgniter project by following the instructions given in readme file.

I have created a class to initialize the connection & other settings. The contents of the class are:

use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;

class Capsule extends CapsuleManager {

  function __construct()
  {
    $ci = &get_instance();
    $db = $ci->db;
    $this->addConnection(array(
      'driver'    => $db->dbdriver,
      'host'      => $db->hostname,
      'database'  => $db->database,
      'username'  => $db->username,
      'password'  => $db->password,
      'charset'   => $db->char_set,
      'collation' => $db->dbcollat,
      'prefix'    => $db->dbprefix,
    ));

    $this->setEventDispatcher(new Dispatcher(new Container));

    // Make this Capsule instance available globally via static methods... (optional)
    $this->setAsGlobal();

    // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
    $this->bootEloquent();
  }
}

When I initiailze the above class, it gives me an error

Call to a member function instance() on a non-object 

with stack trace to

\illuminate\database\Illuminate\Database\Capsule\Manager.php

at Line 216

public function setEventDispatcher(Dispatcher $dispatcher)
{
    $this->container->instance('events', $dispatcher); //Line 216
}

My composer.json uses

"illuminate/database": "@dev"
anlutro commented 10 years ago

Don't override the constructor. You have not followed the instructions at all.