K
K
kanuhamru2017-02-05 18:16:20
Yii
kanuhamru, 2017-02-05 18:16:20

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?

  1. From which class should the Post model be inherited or which interface should be implemented so that it behaves like a regular ActiveRecord?
  2. What methods to implement, given that you only need to read, but you don’t need to create, edit and delete?

Next, you will need to similarly implement Post-related models: Tag, Category, Author, the source of which will also be XML-RPC.
I will be glad for any hints.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
padlyuck, 2017-02-05
@kanuhamru

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

Z
Zhainar, 2017-02-05
@zhainar

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.

K
kanuhamru, 2017-02-05
@kanuhamru

I found an implementation of ActiveRecord, which uses files (not SQLite) instead of a database. I think I'll find most of the answers there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question