Zend框架DBTABLE插入()插入记录两次

问题描述:

我有一个控制器的动作如下Zend框架DBTABLE插入()插入记录两次

public function reportcommentAction() { 
    $comment_id = $this->getRequest()->comment_id; 

    $blockedCommentTable = new Application_Model_DbTable_BlockedComments(); 
    $blockedCommentTable->blockComment($comment_id, $this->user_id); 

} 

这使得调用blockComment()DBTABLE模型,它看起来像这样

class Application_Model_DbTable_BlockedComments extends Zend_Db_Table_Abstract { 

protected $_name = 'blocked_comments'; 

public function blockComment($comment_id, $blocked_by) { 

    if (!empty($comment_id) && !empty($blocked_by)) { 
     $data = array(
      'comment_id' => $comment_id, 
      'blocked_by' => $blocked_by 
     ); 

     $this->insert($data); 
     exit; 
    } 

} 

对于一些原因,我需要那个退出;最后。没有它,我会插入2条记录,而不是像预期的那样。

我在blocked_comments表中有3个字段,即id,comment_id和被阻止。在退出声明到位的情况下,我会按预期得到值为1,21,1的记录。没有退出声明,出于某种原因,我得到了值为2,0,1的额外记录。

我有相同的代码(没有多余的退出)在我的代码的其他部分工作,我不知道这里发生了什么。

+0

应该很容易看到,如果你有像xdebug的东西。你确定这个方法没有被调用两次? – JohnP 2011-12-19 12:37:13

+0

@JohnP它肯定看起来像被称为两次,但我不知道如何。我会看看我是否可以用xdebug完成它。 – 2011-12-19 12:55:52

+0

我已经使用调试器运行了该项目,并且正在调用两次reportcommentAction。它第一次被正确调用,并且Request_Uri报告/ us/account/report-comment/21,其中21是comment_id参数。第二次,Request_Uri报告/us/account/report-comment/default.appcache?v=1这对我来说毫无意义。 – 2011-12-19 13:45:10

The second time round the Request_Uri reports /us/account/report-comment/default.appcache?v=1 

主HTML标签(右顶部)取下manifest属性摆脱了第二个电话的。 Zend的应用程序路由似乎在踢,而不是提供静态文件。这可能是因为该文件不存在或可能存在于不同的路径上。

我有类似的问题。为什么->insert被称为两次的原因是因为这些:

public function saveAction() 
{ ... 
    $result = $this->_bookModel->saveBook($data); 
    if ($result) { 
     $this->view->form = $form->reset(); 
     $this->_helper->viewRenderer('index'); 
    } 

我已经取代

$this->_helper->viewRenderer('index'); 

return $this->_helper->redirector('index'); 

和它的工作完美。