无法删除论坛中的帖子。 (CakePHP的)

时间:2010-12-20 19:50:22

标签: cakephp forums android-1.5-cupcake

我在CakePHP中使用Cupcake论坛插件。有一个表单用于选择所需的帖子,然后提交表单以删除帖子。表格数据显然是同时使用POST和GET方法发送到'主题'控制器内的'中等'功能。该函数首先检查发送的数据是否为POST。但是,当收到数据时,它表明它是GET。同事程序员和我不想完全改变别人的内部代码,但我们无法弄清楚这两种方法如何发送数据并作为GET接收。插件中的代码如下:

-------------- moderate.ctp(查看)---------------------

<?php echo $form->create('Post', array('url' => array('controller' => 'topics', 'action' => 'moderate', $topic['Topic']['slug']))); ?>

------------- topics_controller.php(controller)-------

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-&gt; RequestHandler-&gt; isPost())'永远不会成立;因此,提交的帖子不会被删除。我们缺少什么?

1 个答案:

答案 0 :(得分:0)

尝试将moderate.ctp更改为

<?php 
echo $form->create('Post', array(
    'url' => array(
        'controller' => 'topics', 
        'action' => 'moderate', 
        $topic['Topic']['slug'],
     ),
    'type' => 'post',
)); 
?>