My problem is: I have some script that is displaying some file. I want to add feature that after downloading this file it is automatically added to history. Where i can download it from there again. This is code that is displaying my pdf file:
$model = $this->loadModel($id);
if (! $model->isStatus(LoanStatus::STATUS_CURRENT)) {
Report::set(Report::ERROR, Yii::t('app', 'Monits a avilable only for current loans'));
$this->redirect($this->createUrl('loan/view', ['id'=>$model->primaryKey]));
}
$monitBase64 = $model->getMonit($model->client);
if ($monitBase64 === null) {
Report::set(Report::ERROR, Yii::t('app', 'There is no monits for this client'));
$this->redirect($this->getId());
}
header('Content-Type: application/pdf');
echo base64_decode($monitBase64);
Yii::app()->end();
At the moment i can only add this file to a history manually. My history looks like that:
<div class="col-md-2">
<?php echo $form->dateField($model, 'date', ['class' => 'form-control btn-rect', 'placeholder' => 'YYYY-MM-DD']); ?>
<?php echo $form->error($model, 'date'); ?>
</div>
<div class="col-md-7">
<?php echo $form->textField($model, 'description', ['class' => 'form-control btn-rect', 'placeholder' => 'Opis']); ?>
<?php echo $form->error($model, 'description'); ?>
</div>
<div class="col-md-2">
<?php echo $form->fileField($model, 'file', ['class' => 'form-control btn-rect', 'placeholder' => 'Plik']); ?>
<?php echo $form->error($model, 'file'); ?>
</div>
<div class="col-md-1">
<?php echo GxHtml::submitButton(Yii::t('app', 'Save'), array('class' => 'btn btn-success btn-rect pull-right'));?>
</div>
<?php $this->endWidget(); ?>
</div>
<?php if ($files !== null) { ?>
<?php foreach ($files as $file) { ?>
<tr>
<td><?= $file->date; ?></td>
<td><?= $file->description; ?></td>
<td><?= $file->file; ?></td>
<td>
<a href="<?= $this->createUrl('/loanFile/download/id/' . $file->primaryKey); ?>" class="btn btn-xs btn-info btn-rect">Pobierz</a>
</td>
</tr>
<?php } ?>
<?php } ?>
Everything in this code is dont manually. I chose date manually, description and file as well. What should i do to add file to history after downloading it. For without description and date i just want to understand how should it be done. Any suggestions?