我在我的index.php這個代碼在我觀點:的Yii 2 GridView的鏈接無法使用
<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'],
],
]); ?>
我已經顯示的特定文件的鏈接/路徑,當我點擊它,沒什麼發生。當我把它懸停時,我可以看到鏈接,例如:file:///C:/wamp3/www/basicaccounting/web/pdf/attachment.pdf
,在狀態欄(頁面的左下角)。我也試過右鍵單擊+在新標籤中打開,網址只是about:blank
。
我也嘗試了每個這些註釋的返回語句,仍然是相同的結果。
對此有何想法?
編輯:
我的問題是我的文件路徑,即文件:/// C:/wamp3/www/basicaccounting/web/pdf/attachment.pdf 我在鏈接路徑需要相對於文檔根目錄ie /basicaccounting/web/pdf/attachment.pdf,而不是C驅動器。
所以,我想:
'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'));
}
現在它工作正常。
「$ data-> image」中存儲了什麼?你能提供一個例子嗎?和期望的輸出的例子。 – arogachev 2015-02-12 06:02:01
@arogachev我使用了'var_dump()'來顯示'$ date-> image'裏面的內容。這裏有一個例子:'string'C:/wamp3/www/basicaccounting/web/uploads/dcc.jpg'(length = 48)' – kaynewilder 2015-02-12 06:10:33
你想從那個字符串創建什麼鏈接? – arogachev 2015-02-12 06:11:47