나는 이것을 내 컨트롤러에 가지고 있습니다.CakePHP : 안전하게 레코드를 삭제하는 올바른 방법
public function delete($id) {
if($this->request->is('get')) {
throw new MethodNotAllowedException();
}
$this->Memberlist->id = $id;
if (!$this->Memberlist->exists()) {
throw new NotFoundException(__('Invalid list.'));
}
if ($this->Memberlist->delete()) {
$this->Session->setFlash(__('List deleted.'), 'success');
return $this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('List was not deleted.'), 'error');
return $this->redirect(array('action'=>'index'));
}
내 모델은 다음과 같습니다 (belongsTo를)
내보기 중 하나에서<?php
class Memberlist extends AppModel {
public $name = 'Memberlist';
public $belongsTo = array(
'Account' => array(
'className' => 'Account',
'foreignKey' => 'account_id'
)
);
, 나는 이런 식으로 뭔가가 :
echo $this->Form->postLink('Delete',
array('action' => 'delete', $list['Memberlist']['id']),
array('class'=>'btn-mini btn', 'confirm' => 'Are you sure?'));
과 같은 HTML을 생성 :
를<form id="post_4fe15efc0d284" method="post" style="display:none;" name="post_4fe15efc0d284" action="/Grid/memberlists/delete/9">
<input type="hidden" value="POST" name="_method">
<input id="Token1627936788" type="hidden" value="8756f7ad21f3ab93dd6fb9a4861e3aed4496f3f9" name="data[_Token][key]">
<div style="display:none;">
</form>
<a class="btn-mini btn" onclick="if (confirm('Are you sure?')) { document.post_4fe15efc0d284.submit(); } event.returnValue = false; return false;" href="#">Delete</a>
문제는 Firebug (또는 개발자 도구)를 사용하여 action="/Grid/memberlists/delete/9"
에있는 ID
을 업데이트하면 아무 것도 삭제할 수 있습니다! 다른 계정에서도. 보안 구성 요소가 켜져 있어도.
이 작업을 수행하는 올바른 방법은 무엇입니까? 현재 로그인 한 사용자의 account_id에 대해 account_id
을 확인하려고합니다. CakePHP가이 문제를 해결할 수있는 무엇인가를 가지고 있다면 궁금합니다.
내가 CakePHP의 새로운 오전이 대답은 구현하기가 매우 단순하게 발견했다. 또한 모델에서이 작업을 수행하는 데 많은 의미가있었습니다. – wenbert