【问题标题】:Can't delete posts in forum. (CakePHP)无法删除论坛中的帖子。 (CakePHP)
【发布时间】:2010-12-20 19:50:22
【问题描述】:

我在 CakePHP 中使用 Cupcake Forum 插件。有一个表格用于选择所需的帖子,然后提交表格以删除帖子。表单数据显然正在同时使用 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(控制器)--------

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

【问题讨论】:

    标签: cakephp forums android-1.5-cupcake


    【解决方案1】:

    尝试将moderate.ctp 更改为

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多