Varshaan Varshaan - 4 months ago 13
PHP Question

$http.get(url for my function in index.php) returns 404 error when callin my slim php function

I am getting a 404 response when I use

$http.get
to fetch the list of users from my backend API, which is built using Slim.

This is my AngularJS method to call

function ListCtrl($scope, $http) {
$http.get('api/getuser.php/getUser').success(function(data) {
$scope.users = data;
});
}


This is my Slim route, located in
getuser.php
:

$app = new Slim();
$app->get('/getUser', 'getUser');
$app->run();

function getUser() {
$sql = "select * FROM employees ORDER BY id";
try {
$db = getConnection();
$stmt = $db->query($sql);
$wines = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($wines);
} catch(PDOException $e) {
echo '{"error":{"text":"'. $e->getMessage() .'"}}';
}
}


Thanks for replies in advance:)

Answer

Don't you need to register a function instead of a string?

Try:

$app->get('/getUser', getUser);

http://docs.slimframework.com/routing/get/

Comments