开发者

CakePHP Method Will Not Process Data AT ALL

I have a problem my code below will not process at all. It will not save or delete. I get a success message but nothing will save nor will nothing delete. I thought the method was a reserved keyword but then I tried to rename it and it still didn't work. Any insight would be enormously appreciated as this has stumped me.

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')
         开发者_JAVA技巧               $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());
    }
}


The save will try to validate unless you give $this->Article->save($this->data,array('validate' => false))

You can try out these tips

try this too

            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');
            }


I think you need

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

You should also check that there are no callbacks that are preventing it from being saved in the model code. Make sure that you turn on debug to level 2 in the app/config/core.php file and look at the sql queries that get output before redirecting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜