You could build your own custom data provider class. You can extend it from CDataProvider
and implement the missing abstract
methods:
abstract protected function fetchData();
abstract protected function fetchKeys();
abstract protected function calculateTotalItemCount();
Notice, that your storage model already comes very close to these methods: You store the IDs in one database and the actual data in another. So you can focus on one DB at a time in each of these methods.
You'd start with fetchKeys()
. There you need to query the keys (=IDs) from your second database. Have a look at CSqlDataProvider::fetchData()
to see how to use the CPagination
object from $this->getPagination()
to find out the current limit
and offset
. If you need sorting you'd also inspect the CSort
object from $this->getSort()
for current sort settings. With all that data available you should be able to build the query for the IDs on the currently requested result page.
Then in fetchData()
you can obtain those keys through $this->getKeys()
. You should not call fetchKeys()
directly, because with getKeys()
the result from fetchKeys()
is "cached", so if it's called again later in the same request, there won't be another query. With that keys you now can easily query your main database. The result will represent the rows on the current page.
Finally you have to implement calculateTotalItemCount()
. This is very easy again: Just query your second DB for the total number of items.
That's all you need to do - the code in the base CDataProvider
class will take care of the rest and call your methods on demand.