0
I’m having problems with slim DELETE, it shows a 404 error, follow the code:
<?php
require '../Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
$app->get('/', function () {
echo "SlimProdutos Welcome";
});
$app->delete('/produtos2/:id','deleteProduto');
$app->run();
function getConn()
{
return new PDO('mysql:host=localhost;dbname=Slim',
'root',
'mxk8mxk9',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
}
function deleteProduto($id)
{
$sql = "DELETE FROM produtos WHERE id=:id";
$conn = getConn();
$stmt = $conn->prepare($sql);
$stmt->bindParam("id",$id);
$stmt->execute();
echo "{'message':'Produto apagado'}";
}
I only use http and do not use any other page/form to call it
I’m opening him up like this http://localhost/slimTestes/Slimproducts/products2/111 111 is the id I want to delete!
Another question is about the function of Slim, it basically serves to use the POST, GET, PUT, DELETE, etc...with routes and json, right ? it has other uses ?
In your controller you can see the value of
$id
?– rray
how do I do that ?
– Alan PS
Within
deleteProduto()
do,echo $id;
whether the number is at least displayed.– rray
no, gives a 404 slim error "404 Page Not Found"
– Alan PS
For me I had to change only to DELETE FROM products WHERE id= ?
– viana