Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlimPHP Callable does not exist

Tags:

php

slim

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.

like image 704
Dan L Avatar asked Dec 15 '22 07:12

Dan L


2 Answers

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...

like image 146
Mateus Gabi Avatar answered Dec 25 '22 10:12

Mateus Gabi


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.

like image 40
dynamic Avatar answered Dec 25 '22 09:12

dynamic