一.控制器 编辑输出格式
public function actionSee($id)
{
$dd = substr(strrchr($id, "="), 1);//获取id,有直接函数可使用。
$dd = (int)$dd;
$model = $this->findModel($dd);
if ($model->contractFile) {
$fileName = $model->fileName;
$path = '../uploads/contractFile/' . $fileName;
$file = fopen($path, "r+"); // 打开文件
// 输入文件标签
header('Content-type: application/pdf');
header('filename:'.$file);
// 输出文件内容
echo fread($file, filesize($path));
fclose($file);
}
}
二.在视图层触发
'see' => function ($url) {
return Html::a('<span class="">预览</span>',
['contract/see','id' =>$url],
[
'title' => '在线预览',
'data' => [
'method' => 'post',
],
'target' => '_black'
]);
},