I have this code in my index.php in my view:
<p>
<?= Html::a('Create Invoice', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'inv_id',
'cust_name',
'currency',
'inv_date',
'inv_duedate',
'prod_name',
//'prod_desc',
//'prod_quanity',
'prod_price',
//'prod_tax',
//'amount',
//'subtotal',
'total',
[
'attribute' => 'image',
'format' => 'raw',
'value' => function($data){
//return Html::a($data->image, $data->image, $data->image);
return Html::a(Html::encode($data->image),$data->image);
//return Html::a($data->image, $data->image, array('target' => '_blank'));
//return Html::a(Html::encode('file'),'invoice/index');
}
],
//'poso_num',
//'subheading',
//'footer',
//'memo',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
I have already displayed the link/path of a specific file, when I click it, nothing happens. When I hover it, I can see the link, example: file:///C:/wamp3/www/basicaccounting/web/pdf/attachment.pdf
, in the status bar (lower left corner of the page). I also tried right click + Open in New Tab, the url is just about:blank
.
I also tried each of those commented return statements, still the same results.
Any thoughts about this?
Edit:
My problem is with my file path i.e. file:///C:/wamp3/www/basicaccounting/web/pdf/attachment.pdf My path in the link needs to be relative to the document root i.e. /basicaccounting/web/pdf/attachment.pdf, and not in C drive.
So I tried:
'value' => function($data){
$basepath = str_replace('\\', '/', Yii::$app->basePath).'/web/';
$path = str_replace($basepath, '', $data->file);
return Html::a($data->file, $path, array('target'=>'_blank'));
}
Now it works fine.
I think I have solved my own problem.
My problem is with my file path i.e. file:///C:/wamp3/www/basicaccounting/web/pdf/attachment.pdf My path in the link needs to be relative to the document root i.e. /basicaccounting/web/pdf/attachment.pdf, and not in C drive.
So I tried:
'value' => function($data){
$basepath = str_replace('\\', '/', Yii::$app->basePath).'/web/';
$path = str_replace($basepath, '', $data->file);
return Html::a($data->file, $path, array('target'=>'_blank'));
Now it works fine. Thanks everyone!