How to display conditional url and image in Detailview


I have two model, Card (related to db table card, pk card_id) with all mandatory fields and Card_front (related to db table card_front, pk card_id) with the optional fields such as the card’s image, store in the db field card_front as a path.

Card.php model

public function getCardFront()



return $this->hasOne(Card_front::className(), ['card_id' => 'card_id']);


in the card view, I show attribute also of card_front table :

    <?= DetailView::widget([

        'model' => $model,

        'attributes' => [


// this display the card image


    'label'=> 'Card Front',


     //other attributes    



    ]) ?>

as no all cards have an entry in card_front table, is there a way to display an url (e.g. Card Front

index.php?r=card_front%2Fcreate) instead of the default Card Front (not set) in the card view?

Thank you

Something like this ?


  'label' => 'URL',

  'value' => function ($model, $key, $index, $column) {

    return Html::a('link...', ['/card_front/create', 'param'=>'param']);


  'format' => 'raw'


PS: you should enable pretty URL ;)