You’re autoload
array is wrong in your composer.json file. If your root namespace is app
then it should look like this:
{
"autoload": {
"psr-0": {
"app": "/"
}
}
}
You can then use your classes in the app
namespace like this:
<?php
require('../vendor/autoload.php');
$test = new \app\controller\Test();
However, I would camel-case your namespaces, as is the PSR way. So in my case, I have a directory structure like this:
- src/
- MCB/
- Controller/
- PagesController.php
- Controller/
- MCB/
- vendor/
- autoload.php
My composer.json file looks like this:
{
"autoload": {
"psr-0": {
"MCB": "src/"
}
}
}
And I can then use my classes like this:
<?php
require('../vendor/autoload.php');
$controller = new \MCB\Controller\PagesController();