GoodsControllerのaddアクションで購入する商品の値を取ってきてDBに入れる。
↓
ConfirmBuyControllerにredirectして「(購入した商品の名前)を購入しました!」という表示する。
というコードを書いていますが、redirectで購入した商品の値を渡して、表示させる所が上手くいっていません。
(orders tableにはid,name,price,dateのカラムがあります)
GoodsController.php
class GoodsController extends AppController { function order() { $this->autoRender = false; //購入された商品の情報を受け取り、orders tableに保存 if ($this->request->is('post')) { $this->loadModel('Orders'); $order = $this->Orders->newEntity(); $order = $this->Orders->patchEntity($order, $this->request->data); if ($this->Orders->save($order)) { return $this->redirect(['controller' => 'ConfirmBuy' , 'action' => 'index' , $order]); } } } }
ConfirmBuyController.php (rediret先のController)
<?php namespace App\Controller; use App\Controller\AppController; class ConfirmBuyController extends AppController { public function index($order=null) { set('order',$order); } }
ConfirmBuyのtemplate/index.ctp
<div> <h1 style="text-align:center;">SHOP</h1> <h2><?= $order->name ?>を購入しました</h2> </div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。