$http.get(url for my function in index.php) returns 404 error when calling my slim php function
$http.get(url for my function in index.php) returns 404 error when callin my slim php function
当我使用 $http.get
从我的后端 API 获取用户列表时,我收到了 404 响应,该后端是使用 Slim 构建的。
这是我的 AngularJS 调用方法
function ListCtrl($scope, $http) {
$http.get('api/getuser.php/getUser').success(function(data) {
$scope.users = data;
});
}
这是我的修身路线,位于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() .'"}}';
}
}
提前感谢您的回复:)
你不需要注册一个函数而不是一个字符串吗?
尝试:
$app->get('/getUser', getUser);
当我使用 $http.get
从我的后端 API 获取用户列表时,我收到了 404 响应,该后端是使用 Slim 构建的。
这是我的 AngularJS 调用方法
function ListCtrl($scope, $http) {
$http.get('api/getuser.php/getUser').success(function(data) {
$scope.users = data;
});
}
这是我的修身路线,位于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() .'"}}';
}
}
提前感谢您的回复:)
你不需要注册一个函数而不是一个字符串吗?
尝试:
$app->get('/getUser', getUser);