Amjad Sarwar February 2016

how to use function in DetailView yii2

**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);
                  }
    ],
   ],
]) ?>

**i use model function in detail view how i use function in detail view **

Answers


scaisEdge February 2016

In DetailView value don't need anonymous function but only the assign ..

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

],

see yii2 doc


Oyedele Femi February 2016

return Dealer::getName($model->dealer_id)

Write out the code inside the getName function. If you want to get the name of the dealer using its id, then I think you should use the yii\db\ActiveQuery to sort that out. Lemme see your getName function

Post Status

Asked in February 2016
Viewed 2,570 times
Voted 8
Answered 2 times

Search




Leave an answer