我在这里的理解或代码中遗漏了一些东西......
我有一个非常基本的 CRUD 应用程序来列出/添加/编辑/删除类别,当我将表上的主键定义为“id”时它工作正常,但是当我将数据库列重命名为“categoryId”时, PUT url 不包含键值,我最终会因未处理的路径出现 404 错误...
堆:
用于 RESTful 服务的带有 Slim PHP 的 IIS 7.5
// Route excerpt
...
when('/categories', {templateUrl: 'partials/categoryList.html', controller: CategoryListCtrl}).
when('/categories/new', {templateUrl: 'partials/categoryDetail.html', controller: CategoryNewCtrl}).
when('/categories/:id', {templateUrl: 'partials/categoryDetail.html', controller: CategoryEditCtrl}).
...
angular.module('myServices', ['ngResource'])
.factory('Category', function($resource){
return $resource('../api/index.php/categories/:id', {id:'@categoryId'},
{ update: {method:'PUT' } }
);
})
// WORKS when attribute is 'id'
.factory('Category', function($resource){
return $resource('../api/index.php/categories/:id', {id:'@id'},
{ update: {method:'PUT' } }
);
})
// FAILS with 404 when attribute is 'categoryId'
.factory('Category', function($resource){
return $resource('../api/index.php/categories/:id', {id:'@categoryId'},
{ update: {method:'PUT' } }
);
})
当然代码中还有很多其他地方改名了,但是我看到的效果好像和ngResource有关。
第一种方法产生一个有效的 URL...
categories/1?description=null&name=Observation&report=null
/api/index.php
第二个产生这个......
categories?categoryId=1&description=null&name=Observation&report=null
/api/index.php
由于路径格式错误,出现 404 错误。
是否需要另一个参数(或指令或其他东西)来获取要在 URL 中使用的重命名属性?