【发布时间】:2018-04-14 17:11:31
【问题描述】:
我在理解如何使用数组时遇到了一些麻烦,我正在尝试创建一张发票,通过它返回订单的价格和详细信息,我大部分都在工作,但我想显示命令。到目前为止,我的代码如下所示:
public $items;
public function prepareVars() {
$this->items = $this->items();
}
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 < 1) {
$plates = "Total Plates:" . $plates;
} else {
$plates = "";
}
if ($pdfproof === 'yes') {
$pdfproof = 'PDF Proof @ R25.00';
} else {
$hires = '';
}
if ($hires === 'yes') {
$hires = 'HiRes PDF @ R50.00';
} else {
$hires = '';
}
if ($hardcopy === 'yes') {
$hardcopy = 'HardCopy Proof @ R150.00';
} else {
$hardcopy = '';
}
return Response::json([
'pdf' => $pdfproof,
'hires' => $hires,
'hardcopy' => $hardcopy,
'plates' => $plates
]);
}
这是将数据保存在我的数据库中,如下所示:
HTTP/1.0 200 OK
Cache-Control: no-cache
Content-Type: application/json
Date: Thu, 02 Nov 2017 08:26:11 GMT
{"pdf":"PDF Proof @ R25.00","hires":"HiRes PDF @ R50.00","hardcopy":"HardCopy Proof @ R150.00","plates":""}
然后在前端我使用了 twig 函数 {%for%} ,它看起来像这样:
{% set items = __SELF__.items %}
{% for item in items %}
<td>{{ item.pdf }}</br>{{ item.hires }}</br>{{ item.hardcopy }}</br>{{ item.plates }}</br></td>
{% endfor %}
但这不会在前端返回任何内容。
这感觉就像我做错了,因为我是后端开发的菜鸟:P 任何帮助将不胜感激
【问题讨论】:
-
我没有使用 OctoberCMS 但我认为您必须像
{% set items = json_decode(__SELF__.items) %}那样解码项目 json 并测试!!
标签: php laravel backend octobercms