2010-12-20 7 views
0

CakePHP에서 Cupcake Forum 플러그인을 사용하고 있습니다. 원하는 게시물을 선택한 다음 양식을 제출하여 게시물을 삭제할 수있는 양식이 있습니다. 양식 데이터는 POST 및 GET 메서드를 동시에 사용하여 '주제'컨트롤러의 '보통'기능으로 전송됩니다. 함수는 먼저 보낸 데이터가 POST인지 확인합니다. 그러나 데이터가 수신되면 GET임을 나타냅니다. 동료 프로그래머와 나는 다른 사람의 내부 코드를 완전히 바꾸고 싶지 않지만 두 가지 방법으로 데이터가 전송되고 GET으로 수신되는 방식을 파악할 수 없습니다. 플러그인의 코드는 다음과 같습니다.포럼의 게시물을 삭제할 수 없습니다. (CakePHP)

-------------- 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가 아닙니다. 따라서 제출 된 게시물은 삭제되지 않습니다. 우리는 무엇을 놓치고 있습니까?

답변

0

한번에 변경 moderate.ctp

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