问题
Work on API project. Everything good until I have to add a new endpoint (new method too) and I got this Error for my new endpoint, another endpoint run well. Below is error log:
Type: RuntimeException
Message: [{“container”:{}},“getNotification”] is not resolvable
File: /opt/myanime/api/vendor/slim/slim/Slim/CallableResolver.php
Line: 104
Trace
#0 /opt/myanime/api/vendor/slim/slim/Slim/CallableResolver.php(62): Slim\CallableResolver->assertCallable(Array)
#1 /opt/myanime/api/vendor/slim/slim/Slim/CallableResolverAwareTrait.php(45): Slim\CallableResolver->resolve(‘UserController:…’)
#2 /opt/myanime/api/vendor/slim/slim/Slim/Route.php(333): Slim\Routable->resolveCallable(‘UserController:…’)
#3 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#4 /opt/myanime/api/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 /opt/myanime/api/vendor/slim/slim/Slim/App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /opt/myanime/api/src/MyanimeMiddleware.php(121): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 [internal function]: App\MyanimeMiddleware->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#8 /opt/myanime/api/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(App\VestiaMiddleware), Array)
#9 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#10 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#11 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\App->Slim{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#12 /opt/myanime/api/vendor/slim/slim/Slim/App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#13 /opt/myanime/api/vendor/slim/slim/Slim/App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#14 /opt/myanime/api/public/index.php(35): Slim\App->run()
#15 {main}
My routes for new endpoint:
$app->get('/user/notification', 'UserController:getNotification');
My class:
class UserController{
public function __construct($container)
{
// make the container available in the class
$this->container = $container;
}
public function getNotification($request, $response, $args){
//my code here
}
}
my dependencies.php
:
use App\Controllers\UserController;
$container = $app->getContainer();
$container['UserController'] = function ($c) {
return new UserController($c);
};
my composer.json
{
"name": "slim/slim-skeleton",
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
tried to composer dump-autoload
but that did not work.
回答1:
PHP cannot find your class.
- require it in the index.php
- Fix your PSR-0/4 autoload schema and then dump-autoload
回答2:
Not carefully when rsync
to the server. I uploaded to wrong dir Controller
instead Controllers
.
回答3:
I had a similar issue and I get there. In my case, Slim couldn't instanciate the Controller class because it was simply misspelled.
回答4:
'UserController:getNotification'
is not a valid callable based on the code provided. Use either a static function 'UserController::getNotification'
or construct UserController and pass array($controller, "getNotification")
to $app->get()
.
来源:https://stackoverflow.com/questions/46686371/some-method-is-not-resolvable