CakePHP 内で Cupcake Forum プラグインを使用しています。目的の投稿を選択し、フォームを送信して投稿を削除するためのフォームがあります。フォーム データは、POST メソッドと GET メソッドを同時に使用して、'topics' コントローラー内の 'moderate' 関数に送信されているようです。関数は最初に、送信されたデータが POST かどうかを確認します。ただし、データを受信すると、GET であることが示されます。仲間のプログラマーであり、他の誰かの内部コードを完全に変更したくはありませんが、データが両方の方法で送信され、GET として受信される方法を理解できません。プラグインのコードは次のとおりです。
--------------moderate.ctp (ビュー)---------------------
<?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)));
}
}
}
}
}
「Is GET!」の結果を示すログ チェックを追加しました。Cakeのログファイルに. メソッドが GET であるため、ステートメント「if ($this->RequestHandler->isPost())」は決して true ではありません。したがって、送信された投稿は削除されません。何が欠けていますか?