I am trying to use eloquent orm inside codeigniter.
Following is my composer.json file
"require": {
"php": ">=5.5.0",
"illuminate/database": "5.0"
},
"autoload": {
"classmap": [
"application/models"
]
}
In index.php file I have I added
require 'vendor/autoload.php';
I have create Eloquent.php
file in application/models to initiate eloquent
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$CI = & get_instance();
$config = $CI->db;
$pdo = new PDO('mysql:host='.$config->hostname.';dbname='.$config->database, $config->username, $config->password);
$drivers = array(
'mysql' => '\Illuminate\Database\MySqlConnection',
'pgsql' => '\Illuminate\Database\PostgresConnection',
'sqlite' => '\Illuminate\Database\SQLiteConnection',
);
$conn = new $drivers['mysql']($pdo, $config->database, $config->dbprefix);
$resolver = new Illuminate\Database\ConnectionResolver;
$resolver->addConnection('default', $conn);
$resolver->setDefaultConnection('default');
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
following is my Foo.php
model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'models/Eloquent.php');
use Illuminate\Database\Eloquent\Model as Eloquent;
class Foo extends Eloquent
{
public $table = "foos";
}
In Foos.php
controller I have tried something like following
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Foos extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
var_dump(Foo::all());
}
}
But it is returning following error.
Severity: Notice
Message: Undefined property: Foos::$db
Filename: models/Eloquent.php
Line Number: 5
What I am doing wrong?