2011-12-19 34 views
1

我有一個控制器的動作如下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

回答

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

主HTML標籤(右頂部)取下manifest屬性擺脫了第二個電話的。 Zend的應用程序路由似乎在踢,而不是提供靜態文件。這可能是因爲該文件不存在或可能存在於不同的路徑上。

0

我有類似的問題。爲什麼->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'); 

和它的工作完美。