Hi guys, my intention is to get content of pdf file,which has already been uploaded in alias folder. For this, i programmed a method in Controller like this
public function actionFile($filename) {
$storagePath = Yii::getAlias('@pictures');
if (!preg_match('/^[a-z0-9]+\.[a-z0-9]+$/i', $filename) || !is_file("$storagePath/$filename")) {
throw new \yii\base\NotSupportedException ('Die PDF-Datei existiert nicht!');
}
return Yii::$app->response->sendFile("$storagePath/$filename", $filename);
}
I fail calling this method in Controller using link in anonymous function. It will throw out error:
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: frontend\modules\dateianhang\models\Dateianhang::ERMTheorie.pdf
Any ideas, how to implement link correctly. Here is link in GridView:
[
'class' => 'yii\grid\ActionColumn',
'template' => '{anlagen_index} <br>{anlagen_create} ',
'buttons' => [
'anlagen_index' => function ($model, $id) {
$filename="ERMTheorie.pdf";
return Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/file','id' => $id->$filename], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]);
/*return Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/file','filename' => $id->$filename], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]);
this will throw out 'Try to get property of non-object' without $model as parameter in function
}, },
],
],