简体   繁体   English

yii,显示来自具有相同结构的不同表的记录

[英]yii, show records from different tables with same structure

ok, the thing is i am making a setup with something like wordpress multisite setup but i am using Yii 好的,问题是我正在使用类似wordpress的多站点设置进行设置,但是我使用的是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 因此,在这里而不是网站上,我有“商店”,这里有一个创建商店的超级管理员,每个商店现在都有自己的产品表,例如“ shop_1_product”,“ shop_2_product”等等。如果商店所有者想要从各个表中查看产品列表,使用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. -> 1使用本机Php从每个表集中获取数据。 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? 或者->用表名初始化一个模型,然后使用model()-> findAll获取记录,然后用不同的表名重新初始化同一模型,如果可以的话? any help on how to re-init please. 任何有关如何重新初始化的帮助。 :) :)

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 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. 我在yii1中做到了,这是对不同型号的搜索。 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. 我在一个应用程序中具有类似的设置,但是我决定为所有商店保留一张产品表,每种产品都可以在一个或多个商店中使用,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM