我知道這是重複的問題,但我面臨的問題與苗條框架webservices的angularjs。使用angularjs(例如404)發佈瘦身框架?
我創建Web服務來獲得學生網址的記錄是這樣的:
http://www.slim.local/api/getstudent/1
代碼苗條(網絡服務):
//Get Single user
$app->get('/api/getstudent/{id}',function(Request $request, Response $response){
$id = $request->getAttribute('id');
$sql = "select * from student where id = $id";
try{
//Get object db
$db = new db();
//connect
$db = $db->connect();
$stmt = $db->query($sql);
$student = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($student);
}catch(PDOException $e){
echo '{"Error":{"text":'.$e->getMessage().'}';
}
});
上面的代碼正在與郵差測試。
當我們試圖打相同的URL從angularjs其給出404錯誤和網址,這樣創建:GET http://www.slim.local/api/getstudent?id=2 404 Not Found
角代碼:
RoutingApp = angular.module('RoutingApp', ['ngRoute']);
RoutingApp.config([ '$routeProvider', '$locationProvider', function($routeProvider, $locationProvider)
{
$routeProvider
.when('/home', {
templateUrl: 'template/home.html',
controller: 'homeController',
controllerAs: "homeCtrl"
})
.when('/courses', {
templateUrl: 'template/courses.html',
controller: 'coursesController',
controllerAs: "coursesCtrl"
})
.when('/students', {
templateUrl: 'template/students.html',
controller: 'studentsController',
controllerAs: "studentsCtrl"
}).when('/students/:id', {
templateUrl: 'template/studentDetails.html',
controller: 'studentDetailsController',
controllerAs: "studentDetailsCtrl"
})
.otherwise({
redirectTo: '/home',
});
$locationProvider.html5Mode(true);
} ]).controller('studentDetailsController', function($http,$routeParams){
var vm = this;
$http({
url: "http://www.slim.local/api/getstudent",
params: {id:$routeParams.id},
method: "get"
}).then(function(response){
vm.student = response.data;
});
});
我們怎樣才能搭配超薄API angularjs網址與查詢字符串的網址?
同樣的問題,我也面臨。 –