Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using an array as the data-source for CGridView

Tags:

php

yii

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.

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',
                                                 ....
                                                 ),
                                   ),
               ),

I would then like to do this in my view:

$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.

like image 986
Tom T Avatar asked Mar 02 '12 18:03

Tom T


1 Answers

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,
              ));
like image 95
Mukesh Soni Avatar answered Sep 19 '22 18:09

Mukesh Soni