Hello I have this angularjs http.post() request to slim php framework.
'use strict';
soup.factory('loginService',function($http){
return {
login:function(user){
console.log(user);
var $promise = $http.post('api/vendor/slim/slim',user );
return $promise;
};
});
when I debug the $_POST
it always return an empty array,
but when I use use json_decode(file_get_contents('php://input'))
, slim php will return an error.
this is php function that handle the request.
function login(){
$sql = "SELECT * FROM users ORDER by id";
try {
$db = getConnection();
$stmt = $db->query($sql);
$users = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
//print_r($users);
$users = json_encode($users);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
var_dump($_POST);
$test = json_decode(file_get_contents('php://input'));
//do something with the post data
}
how can I solve this?