Following the guide here
I am able to create the same results but if I change the example and attempt to use the attribute of an express object which is a file link or a date field the view block returns the following error
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
Can the below code be modified to resolve this or is this a core issue?
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
if (isset($entry) && is_object($entry)) {
$drawings = $entry->getDrawings();
?>
<table id="datatable", class="table">
<thead>
<tr>
<th>Drawing Name</th>
<th>Drawing Number</th>
<th>Revision</th>
<th>Revision Date</th>
<th>Category</th>
<th>PDF</th>
</tr>
</thead>
<tbody>
<?php if (count($drawings)) {
foreach($drawings as $drawing) { ?>
<tr>
<td><?=$drawing->getDrawingName()?></td>
<td><?=$drawing->getDrawingNumber()?></td>
<td><?=$drawing->getRevision()?></td>
<td><?=$drawing->getDrawingRevisionDate()?></td>
<td><?=$drawing->getDrawingCategory()?></td>
<td><?=$drawing->getDrawingPdf()?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6">No drawings found.</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
the problem comes from this line:
<?=$drawing->getDrawingPdf()?>
what getDrawingPdf() is returning is a file object so it cannot be output to the screen like a simple string. First, you would have to extract a string from it. For instance, the following code would extract the file name and show it.
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
What this code does is first get the file object which you already had in your code. Then if we have a proper file object, get the file name. If it's not a proper file object (you never now it might have been deleted) we return and empty string. And finally, we output our string $pdfFileName (which is either the filename or an empty string) in your table.
Hope this helps