yii, show records from different tables with same structure

66 views Asked by At

ok, the thing is i am making a setup with something like wordpress multisite setup but i am using Yii

so, here instead of site, i have "shops" there is a super admin who creates shops, each shop has its own table of products like "shop_1_product", "shop_2_product", ..and so on now, if shop owners want to see the list of products from there individual tables, its EASY using CActiveRecord/Models

but I am stuck where the Super user(who creates shops), wants to see the list of products from each table .there are different products in each table so no row duplication, A little help in this stuff, will really be appreciated :)

Approaches I am thinking:

->1 using native Php to get data from each table collectively. OR -> Something like, init a model, with a table name, and then get the records using model()->findAll and then RE-INIT the same model with different table name, if thats possible? any help on how to re-init please. :)

1

There are 1 answers

0
Mihai P. On

You should be able to create a big query and use it as the data provider. http://www.yiiframework.com/doc-2.0/yii-db-query.html#union()-detail

I did this in yii1, it was a search on different models. It should be a little easier for you because the tables should have the same format.

I have a similar setup in an application but I decided to keep 1 table of products for all the shops, each product can be in one or more shops etc.