DBからの商品の情報を表示させ、それを削除する機能を作っていますが削除できません。エラーがでないので逆に何が問題なのかわからずに困っています。goodsテーブルにはid,name,image,priceのカラムがあります。
Template/Admin/index.ctp
<?php foreach($goods as $good): ?> <?= $this->Form->create($good) ?> <h2 style="text-align:center;"><?= h($good->name); ?></h2> <div style="text-align:center;"> <?= h($good->price) ?>円 </div> <div style="text-align:center;"><img src="<?= h($good->image); ?>"></div> <?= $this->Form->button('Delete!'); ?> <?= $this->Form->end() ?> <?php endforeach ?>
Controller/AdminController.php
class AdminController extends AppController { public function delete($id = null) { $good = $this->Goods->get($id); if($this->request->is(['post','put'])){ if($this->Goods->delete($id)){ return $this->redirect(['action' => 'index']); } }else{ $this->set('good',$good); } } }
回答1件
あなたの回答
tips
プレビュー