Reputation: 27
I am trying to use the slim framework to build a website, however I get the following error: "Cannot call index on Store\HomeController because it is not a class nor a valid container entry." I have thoroughly checked for spelling and punctuation errors and found none. The error go's to line 98 of a "callableResover.php file of the following code:
throw new NotCallableException(sprintf(
'Cannot call %s on %s because it is not a class nor a valid container entry',
$callable[1],
$callable[0]
));
This is the HomeController.php file the I created as the following: namespace Store\Controllers;
class HomeController{
public function index(){
echo('Index');
}//end function index
}//end class
And this the route.php file of the code following:
$app->get('/', ['Store\HomeController', 'index'])->setName('home');
Upvotes: 0
Views: 1683
Reputation: 657
I found a problem..
The class is probably registred in /vendor/composer/autoload_classmap.php
so you have to regenerate it with command
composer dump-autoload
and it should work...
Upvotes: 1
Reputation: 758
Assuming your HomeController file is loaded before using it in your route.php
file, try to:
\
to your controller's namespace in the route definition\Store\HomeController
$app->get('/', \Store\HomeController::class . ':index');
Check the Slim documentation to learn more about container resolution
Upvotes: 2