Answer the question
In order to leave comments, you need to log in
Yii2 REST + EmberJS?
I'm trying to make friends with Yii2 as an API with EmberJS.
Everything would be fine, but I'm confused by how Ember and Yii work with model relationships. Yii joins the associated model into a property of the parent, while Ember only wants to see the IDs of the related records in the parent. Essence:
Yii:
'post': {
'id': 1,
'title': 'Post title',
'text': 'some text',
'comments': [
{
'id': 1,
'title': 'some title',
'text': 'some text'
},
{
'id': 2,
'title': 'some title',
'text': 'some text'
}
]
}
'post': {
'id': 1,
'title': 'Post title',
'text': 'some text',
'comments': [1,2]
},
'comments': [
{
'id': 1,
'title': 'some title',
'text': 'some text'
},
{
'id': 2,
'title': 'some title',
'text': 'some text'
}
]
Answer the question
In order to leave comments, you need to log in
If you put async: false in the model field parameters, Ember will wait for the model in the model, as in your first option. But this option is so-so, it's better to look for a ready-made serializer for Yii2 or write your own.
Although the answer is no longer very relevant for the one who asked, but since YII + Ember gives this topic when requested, I will write.
To make Yii2 and Ember 2 friends with each other, in the REST plan (so that Ember requests correspond to Yii2 responses), you need to create an adapter and write the following there:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
defaultSerializer: 'JSONSerializer',
host: 'http://адрес_вашего_api'
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question