我想在双击提交按钮时阻止双重帖子。
我有这段代码来保存数据:
public function reply($id = null){
date_default_timezone_set('Europe/Amsterdam');
date_default_timezone_set('UTC');
$username = $this->Auth->user('username');
$authorRang = $this->Auth->user('rang');
$posts = TableRegistry::get('posts');
$threads = TableRegistry::get('threads');
$query = $threads->find('all');
$last_post_date = date('m/d/Y h:i:s a', time());
$replies = $posts->newEntity();
if ($this->request->is('post')) {
//$token = $this->request->getParam('_csrfToken');
$reply = $posts->patchEntity($replies, $this->request->data);
$reply['thread_id'] = $id;
$reply['author'] = $username;
$reply['created'] = $last_post_date;
$reply['authorRang'] = $authorRang;
$query->update()
->set(['last_post_date' => $last_post_date])
->where(['id' => $id])
->execute();
if ($posts->save($reply)) {
$this->Flash->success(__('Your reply has been saved.'));
//return $this->redirect(['action' => 'view/'.$id.'']);
}else{
$this->Flash->error(__('Unable to add your reply.'));
}
}
$this->set('reply', $replies);
}
我该如何预防?
我尝试了很多东西,但它没有用。我试图取消设置实体,但它不起作用。它仍然会多次保存数据。
由于