Image in gridview

hi guys i wanna add an image inside a grid view. i am using the following code in my view file

<?php

use yii\helpers\Html;

use yii\grid\GridView;

use yii\helpers\Url;

/* @var $this yii\web\View */

/* @var $searchModel app\models\InvoicesSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t(‘app’, ‘Invoices’);

$this->params[‘breadcrumbs’][] = $this->title;

?>

<div class="invoices-index">

&lt;h1&gt; Invoices details&lt;/h1&gt;


	&lt;?= GridView::widget([


    'dataProvider' =&gt; &#036;dataProvider,


    'columns' =&gt; [


        ['class' =&gt; 'yii&#092;grid&#092;SerialColumn'],


         'item_id',


         'item.item_name',


         'item.item_price',


         'item_quantity',


         'total',


       ], 


       [


         'label'=&gt;'Image',


         'format'=&gt;'raw',


         'value' =&gt; function(&#036;data){


             &#036;url = &quot;http://localhost/~user/ims/web/invoice.jpg&quot;;


             return Html::img(&#036;url,['alt'=&gt;'yii']); 


          }


       ],


   


               


]); ?&gt;

</div>

i’m getting Unknown Property – yii\base\UnknownPropertyException

below is my error description

Unknown Property – yii\base\UnknownPropertyException

Setting unknown property: yii\grid\GridView::0

1. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Component.php at line 197


188189190191192193194195196197198199200201202203204205206





                    &#036;behavior-&gt;&#036;name = &#036;value;


 


                    return;


                }


            }


        }


        if (method_exists(&#036;this, 'get' . &#036;name)) {


            throw new InvalidCallException('Setting read-only property: ' . get_class(&#036;this) . '::' . &#036;name);


        } else {


            throw new UnknownPropertyException('Setting unknown property: ' . get_class(&#036;this) . '::' . &#036;name);


        }


    }


 


    /**


     * Checks if a property value is null.


     * This method will check in the following order and act accordingly:


     *


     *  - a property defined by a setter: return whether the property value is null


     *  - a property of a behavior: return whether the property value is null





2. in /home/user/public_html/ims/vendor/yiisoft/yii2/BaseYii.php – yii&#092;base&#092;Component::__set('0', ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]) at line 518


3. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Object.php – yii&#092;BaseYii::configure(yii&#092;grid&#092;GridView, ['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]]) at line 105


4. yii&#092;base&#092;Object::__construct(['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]])


5. in /home/user/public_html/ims/vendor/yiisoft/yii2/di/Container.php – ReflectionClass::newInstanceArgs([['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]]]) at line 372


6. in /home/user/public_html/ims/vendor/yiisoft/yii2/di/Container.php – yii&#092;di&#092;Container::build('yii&#092;grid&#092;GridView', [], ['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]]) at line 151


7. in /home/user/public_html/ims/vendor/yiisoft/yii2/BaseYii.php – yii&#092;di&#092;Container::get('yii&#092;grid&#092;GridView', [], ['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]]) at line 344


8. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Widget.php – yii&#092;BaseYii::createObject(['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure], 'class' =&gt; 'yii&#092;grid&#092;GridView']) at line 95


9. in /home/user/public_html/ims/views/admin/invoice_details.php – yii&#092;base&#092;Widget::widget(['dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider, 'columns' =&gt; [['class' =&gt; 'yii&#092;grid&#092;SerialColumn'], 'item_id', 'item.item_name', 'item.item_price', ...], 0 =&gt; ['label' =&gt; 'Image', 'format' =&gt; 'raw', 'value' =&gt; Closure]]) at line 37


3132333435363738





                 &#036;url = &quot;http://localhost/~user/ims/web/invoice.jpg&quot;;


                 return Html::img(&#036;url,['alt'=&gt;'yii']); 


              }


           ],


 


 


    ]); ?&gt;


&lt;/div&gt;





10. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/View.php – require('/home/user/public_html/ims/views...') at line 325


11. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/View.php – yii&#092;base&#092;View::renderPhpFile('/home/user/public_html/ims/views...', ['searchModel' =&gt; app&#092;models&#092;InvoicedetailsSearch, 'id' =&gt; '7', 'dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider]) at line 247


12. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/View.php – yii&#092;base&#092;View::renderFile('/home/user/public_html/ims/views...', ['searchModel' =&gt; app&#092;models&#092;InvoicedetailsSearch, 'id' =&gt; '7', 'dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider], app&#092;controllers&#092;AdminController) at line 149


13. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Controller.php – yii&#092;base&#092;View::render('invoice_details', ['searchModel' =&gt; app&#092;models&#092;InvoicedetailsSearch, 'id' =&gt; '7', 'dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider], app&#092;controllers&#092;AdminController) at line 367


14. in /home/user/public_html/ims/controllers/AdminController.php – yii&#092;base&#092;Controller::render('invoice_details', ['searchModel' =&gt; app&#092;models&#092;InvoicedetailsSearch, 'id' =&gt; '7', 'dataProvider' =&gt; yii&#092;data&#092;ActiveDataProvider]) at line 213


207208209210211212213214215216217218219





        &#036;searchModel=new InvoicedetailsSearch();


        &#036;dataProvider = &#036;searchModel-&gt;search(Yii::&#036;app-&gt;request-&gt;queryParams,&#036;id);


        return &#036;this-&gt;render('invoice_details', [


                             'searchModel' =&gt; &#036;searchModel,


                             'id'=&gt;&#036;id,


                             'dataProvider' =&gt; &#036;dataProvider,


                            ]);


    }


    public function actionCustomer_invoices(&#036;id)


    {


        &#036;this-&gt;layout='adminHome';


        &#036;searchModel = new InvoicesSearch();


        &#036;dataProvider = &#036;searchModel-&gt;search(Yii::&#036;app-&gt;request-&gt;queryParams, &#036;id);





15. app&#092;controllers&#092;AdminController::actionInvoice_details('7')


16. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/InlineAction.php – call_user_func_array([app&#092;controllers&#092;AdminController, 'actionInvoice_details'], ['7']) at line 55


17. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Controller.php – yii&#092;base&#092;InlineAction::runWithParams(['r' =&gt; 'admin/invoice_details', 'id' =&gt; '7']) at line 151


18. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Module.php – yii&#092;base&#092;Controller::runAction('invoice_details', ['r' =&gt; 'admin/invoice_details', 'id' =&gt; '7']) at line 455


19. in /home/user/public_html/ims/vendor/yiisoft/yii2/web/Application.php – yii&#092;base&#092;Module::runAction('admin/invoice_details', ['r' =&gt; 'admin/invoice_details', 'id' =&gt; '7']) at line 83


20. in /home/user/public_html/ims/vendor/yiisoft/yii2/base/Application.php – yii&#092;web&#092;Application::handleRequest(yii&#092;web&#092;Request) at line 375


21. in /home/user/public_html/ims/web/index.php – yii&#092;base&#092;Application::run() at line 12


6789101112





 


require(__DIR__ . '/&#46;&#46;/vendor/autoload.php');


require(__DIR__ . '/&#46;&#46;/vendor/yiisoft/yii2/Yii.php');


 


&#036;config = require(__DIR__ . '/&#46;&#46;/config/web.php');


 


(new yii&#092;web&#092;Application(&#036;config))-&gt;run();

need some help,

thanks


[ 				'attribute'=>'photo', 

				'format'=>'raw', 	

			'value'=>function ($data) { 		

			return Html::img(Yii::$app->request->BaseUrl.'/images/user/32/'.$data->photo); 		

		},             	'filter'=>false, 			],

Try like this

thanks for the reply, i understood my error i placed the code for displaying image outside the ‘columns’. :)