DetailView image type attribute error

the code.


DetailView::widget([

        'model' => $model,

        'attributes' => [

            'vehicles_id',

            'brand_id',

            'vehicles_name',

            'vehicles_url:url',

            [

                'attribute' => 'vehicles_logo',

                'format' => 'html',

                'value' => function($data) {

                        return Html::img('@CDN/' . $data->vehicles_logo, ['width' => 120]);

                    }

            ]

        ]

    ])



Other code:


 DetailView::widget([

        'model' => $model,

        'attributes' => [

            'vehicles_id',

            'brand_id',

            'vehicles_name',

            'vehicles_url:url',

           [ 

                'attribute' => 'vehicles_logo',

                'format' => 'image',

                'value' => function($data) {

                        return  $data->vehicles_logo;

                    }

            ]

]);

1.code is Error:


Object of class Closure could not be converted to string

 in /Applications/MAMP/htdocs/xxxx.com/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer.php at line

298

2.code Error


strncmp() expects parameter 1 to be string, object given

  in /Applications/MAMP/htdocs/xxxx.com/vendor/yiisoft/yii2/BaseYii.php at line

131

vehicles_logo is value : ‘vehicles/alfa-romeo/alfa-romeo-alfa-4c.jpg’

what is problem?

Did you try ‘format’ => ‘raw’ instead of html?!

Using format:raw,




 [

    'attribute' => 'vehicles_logo',

    'format' => 'raw',

    'value' => function($data) {

     return Html::img('@CDN/' . $data->vehicles_logo, ['width' => 120]);

     }

  ],



Error message:




Object of class Closure could not be converted to string

 in /Applications/MAMP/htdocs/xxxxx/vendor/yiisoft/yii2/widgets/DetailView.php  at line 154



in DetailView you cannot use function as return value.

instead of


'value' => function($data) {

                        return  $data->vehicles_logo;

                    }

do this:


'value' => $data->vehicles_logo,