Ich habe Probleme zu verstehen, wie man mit Arrays arbeitet, ich versuche eine Rechnung zu erstellen, wo der Preis und die Details einer Bestellung zurückgegeben werden, das meiste funktioniert, aber ich möchte es anzeigen die Artikel der Bestellung. so weit sieht mein Code wie folgt aus:OctoberCMS Arbeiten mit Arrays
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
]);
}
Dies wird die Daten in der Datenbank wie folgt zu speichern:
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":""}
Dann am vorderen Ende Ich bin mit dem Zweig Funktion {% für%} und es sieht so aus:
{% set items = __SELF__.items %}
{% for item in items %}
<td>{{ item.pdf }}</br>{{ item.hires }}</br>{{ item.hardcopy }}</br>{{ item.plates }}</br></td>
{% endfor %}
Aber das gibt nichts am Frontend zurück.
Das fühlt sich an wie ich das alles falsch, wie ich ein noob mit Backend-Entwickler bin tue: P Jede mögliche Hilfe bei stark
Ich benutze OctoberCMS nicht, aber ich denke, Sie müssen die Elemente JSON wie diese dekodieren '{% set items = json_decode (__ SELF __. Elemente)%} 'und testen !! – Maraboc