-1

I am new to slim,so please bear with me. I have project structure like

\slim
  \public
    index.php
    
  \src
    \controllers
         \reports
        BillingReportController.php
       \routes
         router.php
       \config
         db.php

But whenever I call the controller via route it gives me below error

"PHP Fatal error: Class 'src\controllers\reports\BillingReportController' not found in /var/www/html/apimod/public/index.php on line 13"

As for the line mentioned in error the snippet is as follows.

index.php

$container = $app->getContainer();
$container['BillingReportController'] = function($container){
    return new \src\controllers\reports\BillingReportController;
}; 

router.php

$app->group('/report', function() use ($app) {

  $app->get('/billing', 'BillingReportController:billing');
});

BillingReportController.php

namespace src\controllers\BillingReportController;

class BillingReportController{
    public function billing($request, $response){
        //my code goes here
    }
}

Can anyone please point out the error.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133

1 Answers1

0

You must've to use autoloading in your composer. something like this.

"autoload": {
"psr-4": {
  "src\\": "src"
 }
}

then in your terminal enter this command

composer dump-autoload

it should fix your problem

Amiros
  • 1