I have an api using the Slim framework (version 3). The project structure has an api directory in the root directory. In it I have dirs for "controllers", "models", "public", "src", etc., as well as my composer.json and vendor (once running composer install). My controllers all have the namespace "App\Controllers" and the composer.json has
"psr-4": {
"App\\": ""
}
defined in autoload. While hitting a route, I am calling my controllers (ex. App\Controllers\AccountController:login). All of this works fine in my vagrant environment, but as soon as I upload it to my production server (shared host and I dropped the entire api dir from my local environment to the public_html dir in the shared host), I get
Type: RuntimeException
Message: Callable App\Controllers\AccountController does not exist
File: /home/downunde/public_html/api/vendor/slim/slim/Slim/CallableResolver.php
Line: 62
#0 /home/downunde/public_html/api/vendor/slim/slim/Slim/CallableResolverAwareTrait.php(45): Slim\CallableResolver->resolve('App\Controllers...')
#1 /home/downunde/public_html/api/vendor/slim/slim/Slim/Route.php(314): Slim\Routable->resolveCallable('App\Controllers...')
#2 /home/downunde/public_html/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#3 /home/downunde/public_html/api/vendor/slim/slim/Slim/Route.php(297): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#4 /home/downunde/public_html/api/vendor/slim/slim/Slim/App.php(441): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 /home/downunde/public_html/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /home/downunde/public_html/api/vendor/slim/slim/Slim/App.php(337): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 /home/downunde/public_html/api/vendor/slim/slim/Slim/App.php(298): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 /home/downunde/public_html/api/public/index.php(52): Slim\App->run()
#9 {main}
Both servers are apache, PHP v. 5.6. I confirmed it is properly hitting the route, but on the shared host it cannot find my controllers.
you should edit your composer.json
like that:
"autoload": {
"psr-4": {
"App\\": ""
}
},
"require": {
// ...
},
"scripts": {
// ...
}
and dependencies.php
// PagesController
$container['PagesController'] = function ($container)
{
return new \App\Controller\PagesController;
};
next, you update your autoload
$ composer dump-autoload -o
Sorry for my english...
Probabily it's a case problem. If locally you are on windows remember that you are case-insensitive.
When you are on Linux you get a case-sensitive environment.
Case problem with Windows-Linux are a common problem. Try to use vagrant or any other approach to have the same environment both local and non-local.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With