I’m a beginning PHP developer. I have an app I’ve written that I would like to rewrite using Yii. Most of it is pretty straight-forward so far but I have one view in the current app that the company using the app loves and I doubt they will want it to change.
In this view there is a form that looks a lot like a spreadsheet (lots of rows and columns to input quantities). The first column of the form is the name of an item, the other 7 columns represent the quantity of the item for each day of the week. Each cell represents an order for the row item and column date and has an input box.
In the database, each individual order is a row in the database and there is only one date column for each order obviously. Rigging up the view was easy enough in pure PHP, but I have no idea how to do this with Yii.
Yii’s CGridView seems to map database columns to columns in the data grid table. I can’t figure out how to have 7 columns in the grid view, one for each day of the week when the database only has one date column. According to the documentation in CGridView each row corresponds to one data item. In my view each row would need to be 7 data items.
The question(s):
Is there any way to do this with Yii right now?
Would writing an extension be a good solution?
Is Yii not going to help me at all with this view? Or is there something besides CGridView?
If Yii can do it, where do I start? Something in CActiveDataProvider, extending CDataColumn, tweaking the model?
I’m not really sure how to proceed, and don’t want to get too far into porting the app to Yii if it’s not appropriate. Hopefully this was clear enough to convey what the issue is. Thanks in advance.
One option would be to create some relations for your items table. I assume they are already related to the order table. You could create a STAT relation for each day of the week in your items model, for example:
(where
item_idis the fk for Items in your Orders table, andorder_dateis a timestamp in your Orders table of when the order was made)In the example above you should be able to grab all the items from the table and get each items total sales for Sunday like so
And pop in a CGridView like so:
Not tested it, but I hope that gives you something to go on.