简体   繁体   中英

$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:)

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

Try:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM