EmberJS: change url for loading model (ember-data)

不问归期 提交于 2019-12-03 06:22:07

This is as of Ember Data Beta 3

To take care of the prefix, you can use the namespace property of DS.RESTAdapter. To take care of the suffix, you'll want to customize the buildURL method of DS.RESTAdapter, using _super() to get the original functionality and modifying that. It should look something like this:

App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '~me/test',
    buildURL: function() {
        var normalURL = this._super.apply(this, arguments);
        return normalURL + '.php';
    }
});

MilkyWayJoe is right, in your adapter you can define the namespace.

App.Adapter = DS.RESTAdapter.extend({
  namespace: '~/me/test'
});

This would work too:

App.Person = DS.Model.extend({
    url: '~me/test/persons',
    firstName: attr('string'),
    lastName: attr('string'),
});

Or if you want to use a namespace and .php path:

App.Adapter = DS.RESTAdapter.extend({
  namespace: '~/me/test',
    plurals: {
        "persons.php": "persons.php",
    }
});

App.Person = DS.Model.extend({
    url: 'persons.php',
    firstName: attr('string'),
    lastName: attr('string'),
});

The plurals bit is to make sure Ember Data doesn't add an 's', e.g. person.phps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!