2012-09-19 30 views
1

添加列下面我在admin.php的視圖文件,型號爲ComponentsPHP警予CGridView從不同的模型

<?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', 
     ), 
    ), 
)); ?> 

我想添加一個名爲資產數量額外的列是在另一場型號爲FixedAsset。這兩張桌子在模型ComAsset中與他們的PK連接在一起。我非常的努力實現的是檢查每個記錄在Components,看看它是否通過component_id鏈接如果是從ComAsset

關係

組件使用fixed_asset_idFixedAsset然後拉出original_asset_number - comasset = 1:1

fixedasset - comasset = 1:M

+0

發佈'Components','ComAsset'和'FixedAsset'中的關係 – dInGd0nG

+0

@ dlnGd0nG更新 – shorif2000

回答

0

假設關係在各個模型正確設置你應該能夠通過訪問相關信息在CGridView。如果我從你的描述中得到了正確的關係,本專欄的value部分應該看起來像這樣:$data->comAsset->fixedAsset->name