Concrete5.8 Express 对象无法转换为字符串
Concrete5.8 Express Object could not be converted to String
按照此处的指南进行操作
我能够创建相同的结果,但如果我更改示例并尝试使用作为文件 link 或日期字段的快速对象的属性,视图块 returns以下错误
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
是否可以修改以下代码来解决这个问题或者这是一个核心问题?
<?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 } ?>
问题出在这一行:
<?=$drawing->getDrawingPdf()?>
getDrawingPdf() 是什么returning 是一个文件对象,因此它不能像简单的字符串一样输出到屏幕。首先,您必须从中提取一个字符串。例如,以下代码将提取文件名并显示它。
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
此代码所做的是首先获取您在代码中已有的文件对象。
然后如果我们有一个合适的文件对象,获取文件名。如果它不是一个正确的文件对象(你永远不会现在它可能已被删除)我们 return 和空字符串。
最后,我们在 table.
中输出我们的字符串 $pdfFileName(它是文件名或空字符串)
希望对您有所帮助
按照此处的指南进行操作
我能够创建相同的结果,但如果我更改示例并尝试使用作为文件 link 或日期字段的快速对象的属性,视图块 returns以下错误
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
是否可以修改以下代码来解决这个问题或者这是一个核心问题?
<?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 } ?>
问题出在这一行:
<?=$drawing->getDrawingPdf()?>
getDrawingPdf() 是什么returning 是一个文件对象,因此它不能像简单的字符串一样输出到屏幕。首先,您必须从中提取一个字符串。例如,以下代码将提取文件名并显示它。
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
此代码所做的是首先获取您在代码中已有的文件对象。 然后如果我们有一个合适的文件对象,获取文件名。如果它不是一个正确的文件对象(你永远不会现在它可能已被删除)我们 return 和空字符串。 最后,我们在 table.
中输出我们的字符串 $pdfFileName(它是文件名或空字符串)希望对您有所帮助