i was following alex's how to build a shopping cart lesson and everything's working fine. but then i dont know what im doing wrong so i get this error :
Fatal error: Uncaught Error: Class 'maimana\App' not found in /Applications/MAMP/htdocs/maimana/bootstrap/app.php:13 Stack trace: #0 /Applications/MAMP/htdocs/maimana/public/index.php(3): require() #1 {main} thrown in /Applications/MAMP/htdocs/maimana/bootstrap/app.php on line 13
bootsrap/app.php :
<?php
use Respect\Validation\Validator as v;
use maimana\App as MyApp;
use Slim\Views\Twig;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new MyApp;
$container = $app->getContainer();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'maimana',
'username' => 'rdp46',
'password' => 'littlelion4696',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require __DIR__ . '/../app/routes.php';
Myapp/App.php :
namespace maimana;
use DI\ContainerBuilder;
use DI\Bridge\Slim\App as DiBridge;
class App extends DiBridge{
protected function configureContainer(ContainerBuilder $builder)
{
$builder->addDefinitions([
'settings.displayErrorDetails' => true,
]);
$builder->addDefinitions(__DIR__ . '/container.php');
}
}
anyone know what's going on?
Rename the Myapp
directory to maimana
(note case) and then update your composer.json
to autoload the maimana
namespace.
i.e. ensure that your composer.json has:
"autoload": {
"psr-4": {
"maimana\\": "maimana/"
}
}
This assumes that the maimana
directoryis in the root of your project where the composer.json
file is. Once you have changed composer.json
, you need to run composer dumpautoload
for the changes to take effect.
This is required because there is a one to one mapping between directory name that the PHP file is in and the namespace for the class in that PHP file. As the namespace in your App.php
is maimana
, the directory needs to be maimana
.