我有一个 CDbActiveRecord 设置,并且我有一个 CGridView 类设置的实例作为小部件。
基本上我的最终结果是我需要一个表,但每一行都包含与 Active Record 关联的行的主键。
如:
<tr id="123"> <td> Column value 1 </td> <td> Col 2 </td> <td> Col 3 </td> </tr>
那是我正在寻找的特定行。
这是我到目前为止生成表格的代码。(设置 json 变量是因为它位于控制器内部,并且小部件以 json 形式返回。)
// get the content id for the version list
$contentID_v = Yii::app()->request->getParam("id");
// setup the criteria to fetch related items
$versionCdbCriteria = new CDbCriteria;
$versionCdbCriteria->compare("contentID",$contentID_v);
// setting up the active data provider for the version
$vActiveDP = new CActiveDataProvider("FactsheetcontentVersion", array(
"criteria" => $versionCdbCriteria,
'pagination' => array('PageSize' => $this->paginationSize),
'keyAttribute'=>'vID',
));
$json_data .= $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $vActiveDP,
'columns' => array(
'title',
'created',
'createdBy'
),
'showTableOnEmpty' => 'false',
),true);
这就是它为我的活动记录所产生的。
<div class="grid-view" id="yw0">
<div class="summary">Displaying 1-1 of 1 result(s).</div>
<table class="items"><thead>
<tr><th id="yw0_c0">Factsheettitle</th>
<th id="yw0_c1"><a href="jq/work/admin/index.php?r=factsheetManager/Editor
&id=25601&getV=true&_=1341694154760&FactsheetcontentVersion_sort=created">Created</a>
</th>
<th id="yw0_c2"><a href="jq/work/admin/index.php?r=factsheetManager/
Editor&id=25601&getV=true&_=1341694154760&FactsheetcontentVersion_sort=createdBy">Created By</a>
</th>
</tr></thead>
<tbody><tr class="odd"><td>Distribution</td><td>0000-00-00 00:00:00</td><td>NULL</td></tr></tbody>
</table>
<div title="jq/work/admin/index.php?r=factsheetManager/Editor&id=12&id=25601&getV=true&_=1341694154760" style="display:none" class="keys"><span>8</span></div>
</div>