Hi all,

Im starting to use composer, and have installed a few packages - This thread is about illuminate/database component.

Im clearly misunderstanding something about how i can use the autoloader.

I have the following directory structure:

-app
-assets
-vendor
index.php [Request goes to index.php] - This file includes composers autoloader (psr-4)
composer.json
composer.lock

Inside -app, I have this structure:

-app
--controllers
--models
--views
--framework
---core
----config
----database [containing database.php]

So, in the index.php file i first include the autoloader, then I require('app/framework/core/database/database.php')

In database.php I have this

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
'driver'    => 'mysql',
'host'      => DB_HOST,
'database'  => DB_NAME,
'username'  => DB_USER,
'password'  => DB_PASS,
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',
]);

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

// Setup the Eloquent ORM
$capsule->bootEloquent();

This gives me the following error in index.php on page load:

Fatal error: Class 'Capsule' not found in C:\wamp\www\framework\index.php on line 26

If I insert the above database setup code directly in index.php, it all works fine. But when I have it in an included file, the autoloader doesnt know of the class. The file is included properly, the path is ok as I can echo out stuff.

My composer.json in root looks like this:

{
"name": "Dev/framework",
"description": "MVC framework - All the good stuff from the MVC design pattern..",
"license": "MIT",
"authors": [
    {
        "name": "Jan Klemmensen",
        "email": "xx@hotmail.com"
    }
],
"require": {
    "swiftmailer/swiftmailer": "5.3.*@dev", 
    "imagine/imagine": "dev-master",
    "illuminate/database": "4.0.*",
    "illuminate/cache": "4.0.*",
    "illuminate/filesystem": "4.0.*",
    "illuminate/validation": "4.0.*" 
},
"autoload": {
    "psr-4": {
        "App\\": "app/"
    }
}
}

Is there any composer experienced folks out there, that can point me in the right direction on how to instantiate the vendor illuminate from inside my app directory. I would like to seperate the vendor packages from the system specific config.

I thought that by including the file, it would be the same as if it was written into the file directly..

Any thoughts appreciated,
/Klemme

Found out why...

In the database file being included i had this at first:

use Illuminate\Database\Capsule\Manager as Capsule;

But this apparently doesnt take effect in the file that is including it.

So by writing

use Illuminate\Database\Capsule\Manager as Capsule;

In index.php (For test only, as it would be used in models later on) - It all works fine.

So for anyone hitting this wall, that could be a way to deal with it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.