I have a model of a particular table which is running fine and works great with CGridView. The main issue I have is that I need to display information from other models based on values from the main model.
For example, lets say I have a "main model" called "Customers." They have some kind of field that indicates a kind of ice cream they got with a number. So, in the model -
class Customer extends CActiveRecord {
...
private $iceCreamType; //stores a number (0/1/2) to determine the column to look at
...
}
In another model, "IceCream", it defines what each kind of ice cream is:
class IceCream extends CActiveRecord {
...
private $iceCreamType-1; //Chocolate
private $iceCreamType-2; //Vanilla
private $iceCreamType-3; //Strawberry
...
}
In this case, CGridView is using “Customer” as its main model as that’s where most of the data comes from. My question is, how do I tell CGridView to use Customer::iceCreamType in the data set from the IceCream model to obtain its output value? I guess I’m looking for something like this:
<?php $this->widget( 'zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'name' => 'iceCreamType',
'header' => 'Type of Ice Cream',
'value' => '$iceCreamData[ "iceCreamType-" . $data->iceCreamType ]',
),
...
),
);
Are there any ideas on this? I tried something like this to no avail:
'value' => 'IceCream::model()->findBySQL( "SELECT iceCreamType-" . $data->iceCreamType . " FROM IceCream WHERE ...'" ),
In addition to not working properly, it looks very ugly and isn’t super usable. Any ideas? Thanks!