Viewing File Details
The show() method displays all metadata for a single file record. It provides the same "detail view" pattern as the Basic CRUD chapter's show() method, but instead of editable form fields, it presents read-only information about the uploaded file.
The Controller Method
public function show(): void {
$this->gatekeeper();
$update_id = segment(3, 'int');
if ($update_id === 0) {
$this->not_found();
return;
}
$data = $this->model->get_file_by_id($update_id);
if ($data === false) {
$this->not_found();
return;
}
$data['headline'] = 'File Details';
$data['update_id'] = $update_id;
$data['back_url'] = $this->get_back_url();
$data['view_module'] = 'file_manager';
$data['view_file'] = 'show';
$this->templates->admin($data);
}
The method first checks that a valid ID was provided (segment 3 is greater than 0) and that the record exists. If either check fails, it calls the not_found() helper. On success, it merges the file data with view metadata and passes everything to the admin template.
The View File
<div class="container">
<h1><?= out($headline) ?></h1>
<table class="table">
<tr>
<th style="width: 200px;">
Document Name
</th>
<td><?= out($doc_name) ?></td>
</tr>
<tr>
<th>File Name</th>
<td>
<code><?= out($file_name) ?></code>
</td>
</tr>
<tr>
<th>File Size</th>
<td>
<?= number_format($file_size) ?> bytes
</td>
</tr>
<tr>
<th>File Type</th>
<td><?= out($file_type) ?></td>
</tr>
</table>
<div class="form-group">
<a href="<?= BASE_URL ?>
file_manager/download/<?= $update_id ?>"
class="btn btn-success">
<i class="fa-solid fa-download"></i>
Download File
</a>
<a href="<?= BASE_URL ?>
file_manager/confirm_delete/<?= $update_id ?>"
class="btn btn-danger">
<i class="fa-solid fa-trash"></i>
Delete
</a>
<a href="<?= out($back_url) ?>"
class="btn btn-default">
<i class="fa-solid fa-arrow-left"></i>
Back
</a>
</div>
</div>The detail page displays four pieces of file metadata in a clean table. Below the table, three action buttons let the user download the file, delete it, or return to the manage page.
What Is Not Editable
Unlike the countries module, there is no edit() or update() method in this module. File records represent uploaded files - changing the file_name or file_path after upload would break the link between the database record and the physical file. If a user needs to replace a file, the recommended pattern is to delete the old record and upload a new one.
We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.
Share your thoughts in the Documentation Feedback.