我在 PHP 中使用 SLIM 做我的第一个项目。调用类时,我收到以下错误消息:
错误信息:
Fatal error: Uncaught RuntimeException: App\Controllers\CitasController:getAll is not resolvable in /var/www/html/slim/vendor/slim/slim/Slim/CallableResolver.php:170
Stack trace: #0 /var/www/html/slim/vendor/slim/slim/Slim/CallableResolver.php(109): Slim\CallableResolver->assertCallable()
#1 /var/www/html/slim/vendor/slim/slim/Slim/CallableResolver.php(72): Slim\CallableResolver->resolveByPredicate()
#2 /var/www/html/slim/vendor/slim/slim/Slim/Routing/Route.php(366): Slim\CallableResolver->resolveRoute()
#3 /var/www/html/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\Route->handle()
#4 /var/www/html/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle()
#5 /var/www/html/slim/vendor/slim/slim/Slim/Routing/Route.php(341): Slim\MiddlewareDispatcher->handle()
#6 /var/www/html/slim/vendor/slim/slim/Slim/Routing/RouteRunner.php(84): Slim\Routing\Route->run()
#7 /var/www/html/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\RouteRunner->handle()
#8 in /var/www/html/slim/vendor/slim/slim/Slim/CallableResolver.php on line 170
项目结构:
[ ]
- 作曲家.json
{
"require": {
"slim/slim": "^4.9",
"slim/psr7": "^1.5",
"slim/php-view": "^3.1",
"respect/validation": "^1.1",
"php-di/php-di": "^6.0"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
- 索引.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/../src/App/App.php';
- 应用程序.php
<?php
use Slim\Factory\AppFactory;
require __DIR__ . '/../../vendor/autoload.php';
$app = AppFactory::create();
require __DIR__ . "/Routes.php";
$app->run();
- 路由.php
<?php
use Slim\Routing\RouteCollectorProxy;
$app->group('/api',function(RouteCollectorProxy $group){
$group->get('/citas','App\Controllers\CitasController:getAll');
});
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello world!");
return $response;
});
- CitasController.php
<?php
namespace App\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class CitasController{
public function getAall($request, $response, $arg){
$response->getBody()->write("Hollaaa");
return $response;
}
}