Estoy intentando ejecutar el siguiente código en Slim V.4 para borrar un registro en MariaDB
y no está sucediendo prácticamente nada.
¿Qué podría ser?
$app->delete('/app/user/delete/{id}', function (Response $response, Request $request, $args){
$id = $args['id'];
$sql = "DELETE FROM users WHERE id = '$id'";
try{
$db = new db();
$db = $db->connect();
$stmt = $db->prepare($sql);
$stmt->execute([$id]);
$db = null;
echo '{"notice": "Usuario borrado con éxito"}';
}catch (PDOException $e) {
echo '{"error": {"text": ' . $e->getMessage() . '}';
}
});
En la consola de insomnia dice:
INTERNAL SERVER ERROR 500.
Y en la consola Linux
:
Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must implement interface Psr\Http\Message\ResponseInterface, instance of Slim\Psr7\Request given, called in /home/martyn/APP/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php on line 42 and defined in /home/martyn/APP/src/routes/users.php:72
Stack trace:
#0 /home/martyn/APP/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(42): {closure}(Object(Slim\Psr7\Request), Object(Slim\Psr7\Response), Array)
#1 /home/martyn/APP/vendor/slim/slim/Slim/Routing/Route.php(372): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Psr7\Request), Object(Slim\Psr7\Response), Array)
#2 /home/martyn/APP/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\Routing\Route->handle(Object(Slim\Psr7\Request)) #3 /home/martyn/APP/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#4 /home/martyn/APP/vendor/slim/slim/Slim/Routing/Route.php(333): Slim\MiddlewareDispatche in /home/martyn/APP/src/routes/users.php on line 72
$sql = "DELETE FROM users WHERE id = ?";
y el execute asi:$stmt->execute([$id]);
. La parte del$user= json_decode(...
en principio sobra$app->delete('/app/user/delete/{id}', function (Response $response, Request $request, $args){
Donde tendras disponible el id que se pasa en la ruta en$args['id']