Yii 填充CGridView一对多关系
在我的项目中,一个名为类型的模型与其他模型有多重关系,下面给出了带part的标准Yii 填充CGridView一对多关系,yii,Yii,在我的项目中,一个名为类型的模型与其他模型有多重关系,下面给出了带part的标准 $criteria->with = array( 'category', 'subCategory', 'accountsSupplierPriceDetails' => array( 'with' => 'serviceLevel' ) ); 这种关系
$criteria->with = array(
'category',
'subCategory',
'accountsSupplierPriceDetails' => array(
'with' => 'serviceLevel'
)
);
这种关系就像
- 类型-类别-关系(1-1)
- 类型-子类别-关系(1-1)
- 类型-会计应用程序定价详细信息-关系(1-1)
- AccountsApplicationPriceDetails-服务级别-关系(1-n)
提前感谢。在我的视图中,我创建了一个包含5行的cgridview,其中一行数据使用dropdownlist填充
<div style="width:700px; height:auto;">
<?php
$widget = $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'response-grid',
'dataProvider' => $pickdataset->pickCategorylistingForMain(),
'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
'summaryText' => '',
'ajaxUpdate' => 'response-grid',
'enablePagination' => true,
'pager' => array(
'class' => 'LinkPager',
'cssFile' => false,
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'columns' => array(
array(
'name' => 'id',
'header' => '#',
'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
array(
'type' => 'raw',
'name' => 'categoryExt',
'header' => 'Category',
),
array(
'type' => 'raw',
'header' => 'Sub Category',
'value' => '$data->subCategory->name',
),
array(
'type' => 'raw',
'name' => 'locationExt',
'header' => 'Location',
),
array(
'type' => 'raw',
'header' => 'Name',
'value' => 'CHtml::dropDownList($data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,"",popDropBox($data->masterCategoryServiceLevels), array("class" => "listbox"), array("empty" => "Select a Location"))',
),
array(
'type' => 'raw',
'header' => 'Pick',
'value' => 'CHtml::image(Yii::app()->baseUrl . "/media/images/edit_icon.png",$data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,array("title" => "Select this Combination"))',
),
),));
function popDropBox($data)
{
$list = array();
foreach ($data as $row)
{
$list[$row->serviceLevel->id] = $row->serviceLevel->name;
}
return $list;
}
?>
</div>
该行为
array(
'type' => 'raw',
'header' => 'Name',
'value' => 'CHtml::dropDownList($data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,"",popDropBox($data->masterCategoryServiceLevels), array("class" => "listbox"), array("empty" => "Select a Location"))',
),
并且我使用一个函数来创建下拉数据is
function popDropBox($data)
{
$list = array();
foreach ($data as $row)
{
$list[$row->serviceLevel->id] = $row->serviceLevel->name;
}
return $list;
}
如果您有任何疑问,请发表评论。我可以自由分享。。。祝你有一个美好的一天,朋友们。。。祝福和祈祷。很快,这其实是我的问题。很抱歉如果发现问题并解决它。。谢谢,如果你有机会的话,我很想看看你的答案。谢谢有一个类似的问题,你能提出解决方案吗?我要做的是在网格上的下拉列表中填充一个条目的多个条目。现在我没有密码。但我会在周一把它贴在这里。我不在家。@DroidUser我希望这个答案对你有帮助。在Gridview中可能吗@杰森·贾斯特斯
function popDropBox($data)
{
$list = array();
foreach ($data as $row)
{
$list[$row->serviceLevel->id] = $row->serviceLevel->name;
}
return $list;
}