2016-02-08 35 views
0
**i use model function in detail view how i use function in detail view ** 
<?= DetailView::widget([ 
    'model' => $model, 
    'attributes' => [ 
     'title', 
     'demand', 
     'sell_for', 
     'property_category', 
     'detail', 
     [ 
     'attribute' => 'dealer_id', 
     'format'=>'raw', 
     'value'=> function ($model) { 
     return Dealer::getName($model->dealer_id); 
        } 
    ], 
    ], 
]) ?> 

**我使用模型函數的詳細視圖如何我詳細視圖**如何使用的DetailView功能yii2

回答

0

使用功能在的DetailView值不需要匿名函數,但僅分配..

 [ 
    'attribute' => 'dealer_id', 
    'format'=>'raw', 
    'value'=> Dealer::getName($model->dealer_id); 

], 

see yii2 doc

0

回報經銷商::的getName($模型 - > dealer_id)

寫出getName函數內的代碼。如果你想使用它的id來得到經銷商的名字,那麼我認爲你應該使用yii \ db \ ActiveQuery來排序。讓我看看你的getName函數