2012-11-07 25 views
0

運行條件以查看這是否是新記錄時,出現此致命錯誤,如果是,則創建一個重複的草稿記錄數據庫。致命錯誤:調用非對象symfony 1.4上的成員函數isNew()1.4

的actions.class.php

$this->form = new AlertsForm($active_alert); 
    if ($request->isMethod('post')) { 
     $this->form->bind($request->getParameter('alerts'), $request->getFiles('alerts')); 
     if ($this->form->isValid()) { 
     try { 
      /* check if record is the draft version, and if not create one */ 

      if (!$active_alert->isNew() && !$active_alert['is_preview'] && 
       ($request->getParameter('button_type') != 'publish' || 
       !$this->getUser()->hasPublishingPrivilege())) { 

      $active_alert = $active_alert->createDraft(); 
      $values = $request->getParameter('alerts'); 
      $values['id'] = $active_alert['id']; 
      $this->form = new AlertsForm($active_alert); 
      $this->form->bind($values, $request->getFiles('alerts')); 

      $this->getUser()->setFlash('draft', true); 
      } 

錯誤:

Fatal error: Call to a member function isNew() on a non-object in apps/cms/modules/alerts/actions/actions.class.php on line 35 

如果我在$active_alert運行的var_dump,它返回:

bool(false)

舊的工作versio這段代碼的ns是相同的,所以我不確定這是不是確切的代碼是錯誤的,我只是不知道在哪裏看。

+0

提示:當教條沒有找到在數據庫中的記錄也還給假的。 – 1ed

+0

我們可以看看你如何創建'$ active_alert'? – j0k

回答

1

的致命錯誤是因爲,作爲錯誤信息表明,沒有$ active_alert,即它是一個非對象,你想叫isNew()非對象。

你可以做的是檢查是否有$active_alert的生存確認,如果它(不)新前:

if ($active_alert && !$active_alert->isNew() && !$active_alert['is_preview'] && ...

相關問題