使用数组作为 CGridView 的数据源 [英] using an array as the data-source for CGridView

查看:35
本文介绍了使用数组作为 CGridView 的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这会奏效.我正在编写和开具发票的应用程序,并希望将当前发票保存在可以存放在 blob 字段中的数组中.这也将用于存档更改等.

Im hoping this will work.. Im writing and invoicing application and would like to hold the current invoice in an array which can be housed in a blob field. This would also be used for archive changes etc.

发票的销售项目使用 CGridView 显示.唯一的问题是所有文档都说数据源应该是 IDataProvider.我不想将整个对象存储在我的数据库中,但类似于以下内容:

The sale items of the the invoice are displayed using CGridView. The only thing is all the documentation says the data source is supposed to be an IDataProvider. I don't want to store the entire object in my Db but something similar to this:

invoice->array(
                InvoiceHeader->array(//header information),
                InvoiceItems->array(
                                   item_1->array( 
                                                 item_id-> '1',
                                                 item_count->'3',
                                                 ....
                                                 ),
                                   ),
               ),

然后我想这样做:

$this->widget('zii.widgets.grid.CGridView', array(
               'dataProvider'=>$this->invoiceItems,
              ));

——旁注.永久存储是一系列表,这将用于保存包含浏览器错误等的活动记录.当前系统直接在表中执行此操作,但会导致非并发发票编号和不准确的统计数据.

-- side note. The permanent storage is a series of tables, this would be used to hold active records encase of browser errors, etc. The current system does this directly in the tables but leads to non concurrent invoice numbers and inaccurate stats.

推荐答案

你可以先将你的数组包裹在 CArrayDataProvider 中,然后在 CGridView 中使用 -

you can first wrap your array in CArrayDataProvider and then use it in CGridView -

$invoiceItemsDataProvider = new CArrayDataProvider($this->invoiceItems);
$this->widget('zii.widgets.grid.CGridView', array(
               'dataProvider'=>$invoiceItemsDataProvider,
              ));

这篇关于使用数组作为 CGridView 的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆