Answer the question
In order to leave comments, you need to log in
Yii2: XML-RPC as ActiveRecord - how to implement?
There are several blogs on WordPress. I am writing an application in which I need to implement the ability to create individual links to any article of any blog. It is necessary to calculate statistics, which user, how many visitors attracted.
For the convenience of users, the list of articles should be displayed directly in the application (choose a blog, then an article, click "Create a link", get your individual URL).
I get articles through the yii2-wordpress extension (it uses XML-RPC). There are no problems with this, as well as with creating a link.
It would be desirable to implement the list of articles in the form of ActiveRecord. To work with articles as if they were stored in a database, in general, as with a regular ActiveRecord (read-only).
It will be necessary to make connections (relations) between models:
Link-> getPage ()
Page->getSite()
Site->getPages()
Next, display the list of Page models through a standard GridView with the ability to sort and filter.
The question is how to correctly implement it so that the Page model behaves like a regular ActiveRecord, despite the fact that the data is taken from a remote server, and not from the database?
Answer the question
In order to leave comments, you need to log in
Perhaps the report by Andrey Konenkov in Ivanovo 2016 Yii2 will help you: Working with an external API as with a local database.
slides https://docs.google.com/presentation/d/1YroLIEDhax...
code https://github.com/andkon13/api_record
See how the activerecord model is built several levels lower (connection with the database, getting data, converting data into an object), write your own constructor. But is it not easier (more interesting) to write your own model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question