[英]php yii CGridView add column from different model
The following I have in my admin.php view file, model is Components
我的admin.php视图文件中包含以下内容,模型为
Components
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'components-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
/*'attributes'=>array(
array(
'label'=>'Asset Number',
'value'=>"help",
),
),*/
'columns'=>array(
'component_id',
'description',
'version',
'serial_no',
'purchase_date',
/*'disposal_date',
'model',
'nol',
'manufacturer',
'medium',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I would like to add a extra column called asset number which is a field in another model FixedAsset
. 我想添加一个称为资产编号的额外列,它是另一个模型
FixedAsset
一个字段。 The two tables are linked together with their PK in the model ComAsset
. 在
ComAsset
模型中,这两个表及其PK链接在一起。 What I ideally an trying to achieve is check each record in Components
and see if it linked via the component_id
if so then pull out the original_asset_number
from FixedAsset
using fixed_asset_id
from ComAsset
我非常的努力实现的是检查每个记录中
Components
,看看它是否通过链接component_id
如果是这样,然后拔出original_asset_number
从FixedAsset
使用fixed_asset_id
从ComAsset
relations 关系
components - comasset = 1:1 组件-comasset = 1:1
fixedasset - comasset = 1:M 固定资产-最低资产= 1:M
Assuming the relationships are properly setup in the respective models you should be able to access the related information via $data->relationshipName
in the CGridView
. 假设在各个模型中正确设置了关系,您应该能够通过
CGridView
中的$data->relationshipName
访问相关信息。 If I got the relationships right from your description the value
part for this column should look something like this: $data->comAsset->fixedAsset->name
. 如果我从您的描述中得到正确的关系,则此列的
value
部分应如下所示: $data->comAsset->fixedAsset->name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.