2010-12-14 4 views
0

問題があります。以下のコードは処理されません。保存したり削除したりすることはありません。私は成功メッセージを受け取るが、何も保存されず、何も削除されない。私はこのメソッドが予約済みのキーワードだと思ったが、名前を変更しようとしたがまだ動作しなかった。これが私を困惑させたので、どんな洞察も非常に高く評価されます。CakePHPメソッドはデータを処理しません。

function approve() { 
    $this->set('title', 'Approve Article'); 
    if ($this->RequestHandler->isPost() || $this->RequestHandler->isPut()) { 
     if (empty($this->data['Article']['id'])) { 
      $this->Session->setFlash('No article was passed.', 'message_error'); 
     } else { 
      $this->Article->set($this->data); 
      if ($this->Article->validates()) { 
       if ($this->data['Article']['approved']) { 
        $this->data['Article']['content'] = $this->Safe->filter($this->data['Article']['content']); 
        $role = $this->Auth->user('role'); 
        if ($role == 'Admin') 
         $this->Article->set('updated', strtotime($this->data['Article']['updated'])); 
        else 
         $this->Article->set('updated', time()); 
        $this->Article->set('updated', time()); 
        $this->Article->save(); 
        // Status 
        $status['Status']['type'] = 'Gain'; 
        $status['Status']['amount'] = 20; 
        $status['Status']['created'] = time(); 
        $this->Status->add($this->data['Article']['account_id'], $status); 
        $this->Session->setFlash('The article was approved and status was added.', 'message_success'); 
       } else { 
        $this->Article->delete($this->data['Article']['id']); 
        $this->Session->setFlash('The article was unapproved and deleted.', 'message_error'); 
       } 
      } else { 
       $this->Session->setFlash('Form Errors', 'message_error'); 
      } 
     } 
    } 
    $unapproved_articles = $this->Article->find('count', array('conditions' => array('Article.approved =' => 0))); 
    if ($unapproved_articles == 0) { 
     $this->Session->setFlash('There are no unapproved articles.', 'message_success'); 
    } else { 
     $article = $this->Article->find('first', array('order' => array('Article.created DESC'))); 
     $article['Article']['updated'] = date('d M Y', $article['Article']['updated']); 
     $this->set('article', $article); 
     $this->set('categories', $this->Category->dropdown()); 
     $this->set('accounts', $this->Account->dropdown()); 
    } 
} 
+0

これを試してみてください? – RabidFire

答えて

0

保存するには、あなたが$this->Article->save($this->data,array('validate' => false))

を与えない限り、あなたはこれらのtips

を試してみることができます検証しようとします `ステータス::`行う()を追加しない何あまりに

  if ($this->data['Article']['approved']) { 
       $this->data['Article']['content'] = $this->Safe->filter($this->data['Article']['content']); 
       $role = $this->Auth->user('role'); 
       if ($role == 'Admin') 
        $this->data['Article']['updated']=strtotime($this->data['Article']['updated']); 
       else 
        $this->data['Article']['updated']=time(); 
       if($this->Article->save($this->data)){ 
       // Status 
        $status['Status']['type'] = 'Gain'; 
        $status['Status']['amount'] = 20; 
        $status['Status']['created'] = time(); 
        $this->Status->add($this->data['Article']['account_id'], $status); 
        $this->Session->setFlash('The article was approved and status was added.', 'message_success'); 
       } 
       else{ 
        $this->Session->setFlash('Form Errors', 'message_error'); 
       } 
      } else { 
       $this->Article->delete($this->data['Article']['id']); 
       $this->Session->setFlash('The article was unapproved and deleted.', 'message_error'); 
      } 
0

私はあなたがモデルのコードに保存されているからそれを妨げている何のコールバックがないことも確認する必要があり

$this->Article->save($this->data) 

が必要だと思います。 app/config/core.phpファイルのレベル2にデバッグをオンにし、リダイレクトする前に出力されるSQLクエリを確認してください。

関連する問題