Hi Everyone!
I’m having a bit of an issue with conceptually understanding the way the data grid works and it would be great to get some help please
I have tables as follows:
CREATE TABLE `report` (
`REPORT_ID` double(8,0) NOT NULL AUTO_INCREMENT,
`REPORT_TITLE` varchar(250) NOT NULL,
`REPORT_ITEM_ID` double(8,0) NOT NULL
PRIMARY KEY (`REPORT_ID`)
);
CREATE TABLE `report_item` (
`REPORT_ITEM_ID` double(8,0) NOT NULL AUTO_INCREMENT,
`REPORT_ID` double(8,0) NOT NULL,
`ITEM_ID` double(8,0) NOT NULL
PRIMARY KEY (`REPORT_ITEM_ID`)
);
CREATE TABLE `item` (
`ITEM_ID` double(8,0) NOT NULL
`ITEM_NAME`varchar(250)
PRIMARY KEY (`ITEM_ID`)
);
A report can have many report items (though in practice in almost all cases exactly 1).
I’d like to create a zii.widgets.grid.CGridView form that displays the report id, the report title and the item name and then 2 extra selectable form columns for users to interact with.
I’ve read through these:
http://www.yiiframework.com/doc/api/1.1/CGridView
but I don’t think I’m really understanding the concept properly.
If I do the following:
$model=Report::model();
$criteria=new CDbCriteria();
$criteria->select="`t`.REPORT_ID, REPORT_TITLE, ITEM_NAME";
$criteria->order="REPORT_ID ASC";
$criteria->alias="t";
$criteria->join="LEFT JOIN `report_item` ON `t`.`REPORT_ID` = `report_item`.`REPORT_ID` LEFT JOIN `item` ON `item`.`ITEM_ID` = `report_item`.`ITEM_ID`";
$dataProvider = new CActiveDataProvider($this, array(
'criteria' => $criteria
));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'report-grid',
'dataProvider' => $dataProvider ,
'enablePagination' => true,
'columns' => array(
array('name'=>'REPORT_ID','htmlOptions'=>array('width'=>'5%')),
'REPORT_TITLE',
'ITEM_NAME'
)
));
I get no results, but also no errors. Variations of the same don’t appear to be working.
Does anyone have any good references with lots of examples?
Thanks!!