我将 Slim 更新到版本 4。我必须这样做,因为我遇到了严重错误。
问题#1:在控制台客户端中出现 504 错误,在服务器控制台中键入:Slim: SlimNotFoundException - Not Found。 404.
我的index.php代码如下所示:
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
$resource = new \App\AbstractResource();
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
$app->addRoutingMiddleware();
/**
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
// Run app
$app->get('/people(/(:id)(/))', function($id = null) use ($app, $resource) {
$result = !empty($id) ? $resource->getOneBy('App\Entity\Person', $app, array('id' => $id)) : $resource->getAll('App\Entity\Person', $app);
echo $result;
});
$app->post('/search(/)', function() use ($app, $resource) {
$regNo = $app->request()->post('searchString');
echo $resource->getOneBy('App\Entity\Person', $app, array('regNo' => $regNo, 'status' => 1));
});
$app->run();
?>
上面的index.php位于/page/api/src。
AbstractResource位于/page/api/src/App
Composer.json 指定:
“自动加载”:{ “psr-4”:{ “应用程序”:“/src” } }
对于任何帮助,我都很感激,非常感激。
我能做什么?请帮忙。
$resource = new \App\AbstractResource();
这是做什么用的?问题是这个类无法识别。