Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

php - Some method is not resolvable

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): SlimCallableResolver->assertCallable(Array)
#1 /opt/myanime/api/vendor/slim/slim/Slim/CallableResolverAwareTrait.php(45): SlimCallableResolver->resolve(‘UserController:…’)
#2 /opt/myanime/api/vendor/slim/slim/Slim/Route.php(333): SlimRoutable->resolveCallable(‘UserController:…’)
#3 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): SlimRoute->__invoke(Object(SlimHttpRequest), Object(SlimHttpResponse))
#4 /opt/myanime/api/vendor/slim/slim/Slim/Route.php(316): SlimRoute->callMiddlewareStack(Object(SlimHttpRequest), Object(SlimHttpResponse))
#5 /opt/myanime/api/vendor/slim/slim/Slim/App.php(476): SlimRoute->run(Object(SlimHttpRequest), Object(SlimHttpResponse))
#6 /opt/myanime/api/src/MyanimeMiddleware.php(121): SlimApp->__invoke(Object(SlimHttpRequest), Object(SlimHttpResponse))
#7 [internal function]: AppMyanimeMiddleware->__invoke(Object(SlimHttpRequest), Object(SlimHttpResponse), Object(SlimApp))
#8 /opt/myanime/api/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(AppVestiaMiddleware), Array)
#9 [internal function]: SlimDeferredCallable->__invoke(Object(SlimHttpRequest), Object(SlimHttpResponse), Object(SlimApp))
#10 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(73): call_user_func(Object(SlimDeferredCallable), Object(SlimHttpRequest), Object(SlimHttpResponse), Object(SlimApp))
#11 /opt/myanime/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): SlimApp->Slim{closure}(Object(SlimHttpRequest), Object(SlimHttpResponse))
#12 /opt/myanime/api/vendor/slim/slim/Slim/App.php(370): SlimApp->callMiddlewareStack(Object(SlimHttpRequest), Object(SlimHttpResponse))
#13 /opt/myanime/api/vendor/slim/slim/Slim/App.php(295): SlimApp->process(Object(SlimHttpRequest), Object(SlimHttpResponse))
#14 /opt/myanime/api/public/index.php(35): SlimApp->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 AppControllersUserController;
$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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

PHP cannot find your class.

  1. require it in the index.php
  2. Fix your PSR-0/4 autoload schema and then dump-autoload

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...