Yii - 一页中的多个 CGridView 关系
我有以下关系方案:
1 投资组合 ->每个投资组合中有许多用户 ->每个用户拥有许多产品
实体:投资组合、用户、产品
我想在一页中显示: 1. 投资组合名称 2. 用户的头衔 3. 该用户拥有的所有产品的 CGridView
看来,如果未使用 CGridView,您将适当地填充您的模型,然后使用 foreach 循环遍历每个用户关系,然后循环遍历与该用户相关的产品。并为产品和用户创建一个 render_partial 视图。
但是,我完全不知道如何使用 CGridView 来完成此任务。
任何建议都非常非常感谢!
I have the following relation scheme:
1 portfolio -> Many Users in each Portfolio -> Each User owns many Products
Entities: Portfolio, User, Products
What I would like to display is in one page:
1. The name of the portfolio
2. The title of a user
3. CGridView of all products owned by that user
It seems, if CGridView were not being used, you would populate your model appropriately and then use a foreach loop to loop through each user relation and then loop through the products related to that user. And create a render_partial view for the products and for the user.
However, I am at a complete loss as how to accomplish this with CGridView.
Any advice is much, much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想在 CGridView 中呈现用户的产品吗?
要使用 CGridView 呈现数据,您需要传入 CDataProvider 来填充视图。所以问题是:如何为 HAS_MANY 关系创建 CDataProvider?
令人惊讶的是,
CActiveDataProvider
不支持这种方式的关系。您需要做什么来获取关系并将该数据传递到CArrayDataProvider
中。假设$user->products
关系,你可以这样做:它并不理想,但它有效。此特定技术的功劳如下: http ://learnyii.blogspot.com/2010/12/yii-how-to-display-lated-hasmany-grid.html
You want to render the User's Products in a CGridView?
To render data with a CGridView you need to pass in a CDataProvider to populate the view. So the question is: how do you make a CDataProvider for the HAS_MANY relation?
Surprisingly, the
CActiveDataProvider
does not support relations in this way. What you need to do get the relation and pass that data into aCArrayDataProvider
. Assuming the$user->products
relation,you can do it like this:It's not ideal, but it works. Credit goes here for this specific technique: http://learnyii.blogspot.com/2010/12/yii-how-to-display-related-hasmany-grid.html