我是Slim的新手。 处理API项目。一切都很好,直到我必须添加一个新的端点(新方法),我的新端点得到了这个错误,另一个端点运行良好。以下是错误日志:
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}
我的新终点路线:
$app->get('/user/notification', 'UserController:getNotification');
我的课程:
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
}
}
我的dependencies.php
:
use App\Controllers\UserController;
$container = $app->getContainer();
$container['UserController'] = function ($c) {
return new UserController($c);
};
我的composer.json
{
"name": "slim/slim-skeleton",
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
试图composer dump-autoload
,但这不起作用。请帮忙。
[解决]
rsync到服务器时不小心。我上传到了错误的目录Controller
,而不是Controllers
。
答案 0 :(得分:0)
PHP找不到你的课程。
答案 1 :(得分:0)
rsync
到服务器时不小心。我上传到了错误的目录Controller
,而不是Controllers
。
答案 2 :(得分:0)
我遇到了类似的问题,然后到达了那里。就我而言,Slim无法实例化Controller类,因为它只是拼写错误。
答案 3 :(得分:-1)
'UserController:getNotification'
不是有效的可调用对象。使用静态函数'UserController::getNotification'
或构造UserController并将array($controller, "getNotification")
传递给$app->get()
。