我使用OctoberCMS中的builder插件构建了一个引用/开票系统,我遇到了一个speedbump . 我正在尝试将数组保存到数据库以用作发票的列表项,但是当我尝试在后端查看发票时,我得到以下异常:
htmlentities() expects parameter 1 to be string, array given
我把它写成一个组件,导致问题的部分如下所示:
public function items() {
$plates = Db::table('orders')->where('quote_no', $this->quoteNo())->value('total_plate_qty');
$hires = Db::table('orders')->where('quote_no', $this->quoteNo())->value('req_hires');
$hardcopy = Db::table('orders')->where('quote_no', $this->quoteNo())->value('req_hardcopy_proof');
$pdfproof = Db::table('orders')->where('quote_no', $this->quoteNo())->value('req_pdf_proof');
if ($plates != 0) {
$plates = "Total Plates: " . $plates;
} else {
$plates = "None";
}
if ($pdfproof === 'yes') {
$pdfproof = 'PDF Proof @ R25.00';
} else {
$hires = 'None';
}
if ($hires === 'yes') {
$hires = 'HiRes PDF @ R50.00';
} else {
$hires = 'None';
}
if ($hardcopy === 'yes') {
$hardcopy = 'HardCopy Proof @ R150.00';
} else {
$hardcopy = 'None';
}
return [
'plates' => $plates,
'pdf' => $pdfproof,
'hires' => $hires,
'hardcopy' => $hardcopy
];
}
在数据库中,有问题的列是TEXT类型,我在Builder中的模型类型也是TEXT .
我猜这个问题是在我的模型的视图,但我不确定如何纠正这一点,任何帮助将不胜感激 .
2 回答
好的我现在得到它可能是你正在尝试打印数组而不是字符串{} ..所以如果item是一个数组,它将抛出此错误 .
我想这是你的数据,你想要展示它 . 作为它的多维数组,我们需要2个循环 . 我们假设你有共享$ items变量来查看,所以,
这个链接可以帮助你与循环战斗:https://twig.symfony.com/doc/2.x/tags/for.html
所以在经历了很多挫折后我使用这种方法让它工作:
然后在前端我称之为: