8

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.

1
  • Side note. I needed to add buttons to the gridview but was gettign an error messge when i treid to add a delete button.. Commented Mar 3, 2012 at 2:12

2 Answers 2

14

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,
              ));
Sign up to request clarification or add additional context in comments.

2 Comments

this was the solution i was looking for.. also a more detailed explanation is here: [link]packtpub.com/article/yii-11-using-zii-components[/link]. I do have to make sure that an id item is passed or Yii has crashees.
For me, when using an array, only 10 elements are shown on grid.
4

This is an extension to my issue and solution. Mukesh's answer is 100% correct. but I needed to add buttons to the grid but when I tried to add the delete button I was getting an error. You need to spcify the url in the button array like so:

 array( // delete button
      'class'=>'CButtonColumn',
      'template'=>'{delete}',
      'buttons'=>array(
              'delete'=>array(
                          'url'=>'Yii::app()->controller->createUrl(\'Invoicing/invoiceBody/test\', array(\'id\'=>$data["id"]))',
                        ),
               ),
                                ),

please notice the the id is declared by using:

array('id', $data['id'])

not:

array('id', $data->id)

1 Comment

struggled with this for quite some time. worked like a charm. thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.