1

Here i like to explain my problem clearly,

the below code is used to store the attached file address, in gridview i have make it as a link, so if i click the link it will show the file which is on the link

this is grid view code:

          [
             'label'=>'document_details',
             'format'=>'raw',
             'value' => function($model){
                    $data = $model->document_details;
                    $url = explode(',', $data);
                    $result = "";
                    foreach ($url as $key => $value) {
                        $result .= Html::a($value, $value);
                    }

                    return $result;
                 }
            ],

but the problem is am not able to do it on Detail view, i dont know how to do it.

Nodemon
  • 1,036
  • 2
  • 25
  • 47

1 Answers1

2

UPDATE: From version 2.0.11 it is fine to use a function for value. Have a look at DetailView::$attributes.


Take a look at this official example. It works differently to the GridView. Here you also specify a list of the attributes that should be taken into account. But the way is different: you don't specify a function for where to get the value. Instead you have to tell DetailView the value directly. You could do this:

function createDocDetailUrls($model) {
    $data = $model->document_details;
    $url = explode(',', $data);
    $result = "";
    foreach ($url as $key => $value) {
        $result .= Html::a($value, $value);
    }

    return $result;
}

echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        //... other attributes
        [
            'label' => 'Document details',
            'format'=> 'raw'
            'value' => createDocDetailUrls($model),
        ],
        //... other attributes
    ],
]);

A similar question is here.

robsch
  • 9,358
  • 9
  • 63
  • 104