環境:
PHP5.6
CakePHP2.6.4
View/Products/index.ctp
lang
1<?php echo $this->Html->link('削除', array('controller'=>'products', 'action'=>'delete',$product['Product']['id']),array(),'投稿を削除しますか?'); ?>
ProductsController.php
lang
1public function delete($id=null) { 2 $user = $this->Auth->user('id'); 3 $this->Product->id = $id; 4 $this->Product->saveField('status_id', 2); 5 $this->Session->setFlash('削除しました。'); 6 $this->redirect(array('action'=>'index'));
上記のように、削除リンクをクリックしたときに、削除するProductが
$this->Auth->user('id') = $product['Product']['user_id']
のように、削除対象のProductのuser_idとログインしている自分のidと一致しないと削除できないようにしたいですが、どのようなコードにすればよいですか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。