2017-11-02 6 views
1

配列の操作方法を理解する上で問題があります。注文の価格と詳細が返されたところで請求書を作成しようとしていますが、そのほとんどは作業していますが、注文の項目。これまでの私のコードは次のようになります。OctoberCMS配列を使って作業する

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":""} 

そして、フロントエンドに私は小枝機能{%に対して%}を使用していますし、

{% set items = __SELF__.items %} 
     {% for item in items %} 
     <td>{{ item.pdf }}</br>{{ item.hires }}</br>{{ item.hardcopy }}</br>{{ item.plates }}</br></td> 
     {% endfor %} 

しかし、これはフロントエンドで何も返されません。

私はそれをすべて間違ってやっているように私は、バックエンドのDEVとのnoob午前、これは感じている:大幅

+0

私はOctoberCMSを使用していませんが、この '{%set items = json_decode(__ SELF __。items)%}'のような項目jsonをデコードしてテストする必要があると思います! – Maraboc

答えて

3

を理解さとP すべてのヘルプ私はあなたが必要ないとしてJSONに変換する必要はありません推測

return [ 
    [ 
     'pdf' => $pdfproof, 
     'hires' => $hires, 
     'hardcopy' => $hardcopy, 
     'plates' => $plates 
    ] 
]; 
:Javascriptを

で動作するようにすることはそう簡単にあなたのコードは、これに

return Response::json([ 
    'pdf' => $pdfproof, 
    'hires' => $hires, 
    'hardcopy' => $hardcopy, 
    'plates' => $plates 
]); 

を置き換えます210

テンプレートのようにアイテムをループしているので、配列を送信する必要があります。そのすべてのPHPコードのでjsonの必要はありません。

は、我々は、マスター配列のアイテムを持っているし、我々は、マスター配列をループ我々はその項目を取得するとき、あなたはそれ以上の助けが必要な場合は、各時間(項目

はコメントしてください(項目)を返します。

+0

大きな成功、ありがとうございました! – Gareth

+0

大歓迎:) –

関連する問題