0
我在CakePHP中使用了Cupcake Forum插件。有一個表格用於選擇所需的帖子,然後提交表單以刪除帖子。表單數據顯然是同時使用POST和GET方法發送到'主題'控制器中的'中等'函數。該功能首先檢查發送的數據是否爲POST。但是,收到數據時,它顯示它是GET。一位程序員,我不想完全改變別人的內部代碼,但是我們無法弄清楚這兩種方法如何發送數據,並且以GET的形式接收數據。該插件的代碼如下:無法刪除論壇中的帖子。 (CakePHP)
-------------- moderate.ctp(view)------------------ ---
<?php echo $form->create('Post', array('url' => array('controller' => 'topics', 'action' => 'moderate', $topic['Topic']['slug']))); ?>
------------- topics_controller.php(控制器)-------
public function moderate($id) {
if ($this->RequestHandler->isGet()){
$this->log('Is GET!');
}
$user_id = $this->Auth->user('id');
$topic = $this->Topic->getTopicForViewing($id, $user_id, 'id');
// Access
$this->Toolbar->verifyAccess(array(
'exists' => $topic,
'permission' => $topic['ForumCategory']['accessRead'],
'moderate' => $topic['Topic']['forum_category_id']
));
$this->log('ID: '.$id.'\n');
if ($this->RequestHandler->isPost()){
$this->log('Is POST!');
}
if ($this->RequestHandler->isGet()){
$this->log('Is GET!');
}
$this->log($this->RequestHandler->getReferer());
$this->log(serialize($this->data));
// Processing
if ($this->RequestHandler->isPost()) {
$this->log('INSIDE POST!');
if (!empty($this->data['Post']['items'])) {
$items = $this->data['Post']['items'];
$action = $this->data['Post']['action'];
foreach ($items as $post_id) {
$this->log('Action: '.$action.'\n');
$this->log('PostID: '.$post_id.'\n');
if (is_numeric($post_id)) {
if ($action == 'delete') {
$this->Topic->Post->destroy($post_id);
$this->Session->setFlash(sprintf(__d('forum', 'A total of %d post(s) have been permanently deleted', true), count($items)));
}
}
}
}
}
我們添加了日誌檢查,其中顯示'是GET!'的結果在Cake的日誌文件中。由於該方法是GET,語句'if($ this-> RequestHandler-> isPost())'從來就不是真的;因此,提交的帖子不會被刪除。我們缺少什麼?