2011-09-06 64 views
3

我有我的應用程序的場館模型的編輯記錄的頁面消失。該頁面正在某個階段工作,但現在已經斷開。

在控制器動作

,調試$這 - >數據形式給出的值的預期陣列。然而,在場館模型,在beforeSave調試$這個 - >數據來自相關(HABTM)模型給出僅對字段的值,類別:

app/models/venue.php (line 89) 
Array 
(
    [Category] => Array 
     (
      [Category] => Array 
       (
        [0] => 1 
        [1] => 2 
        [2] => 8 
       ) 

     ) 

) 

什麼可以發生在表單之間的數據提交到控制器的動作,並調用beforeSave?我應該在哪裏調試呢?

感謝

編輯 - 這裏是什麼在$這個 - >數據控制器(實際數據改爲刪除電話號碼,地址等)。

app/controllers/venues_controller.php (line 63) 
Array 
(
    [Venue] => Array 
     (
      [id] => 19 
      [city_id] => 1 
      [user_id] => 130 
      [name] => Acme Zoo 
      [email] => [email protected] 
      [description] => 
Some text... 

      [blurb] => Truncated description... 
      [contact_id] => 
      [address_1] => Acme Zoo 
      [address_2] => Some Road 
      [postcode] => PP9 4DD 
      [telephone] => 010101010101 
      [website] => 
      [latitude] => 55.21222 
      [longtitude] => -2.111111 
      [featured] => 0 
      [active] => 1 
      [flagged] => 0 
      [smg] => 0 
      [smg_custom_icon] => 1 
      [listings] => 1 
      [send_email] => 0 
      [file] => Array 
       (
        [name] => 
        [type] => 
        [tmp_name] => 
        [error] => 4 
        [size] => 0 
       ) 

     ) 

    [Category] => Array 
     (
      [Category] => Array 
       (
        [0] => 3 
        [1] => 6 
        [2] => 10 
       ) 

     ) 

) 

這是我的代碼來保存數據...

if (!empty($this->data)) { 
     if ($this->Venue->save($this->data)) { 
      $this->Session->setFlash('The venue has been saved','success'); 
      $countryId = $this->Venue->City->field('country_id',array('id'=>$this->data['Venue']['city_id'])); 
      if (!empty($this->data['Venue']['send_email'])){ 
       $this->_emailVenue($this->Venue->id,'venue_added',$countryId); 
      } 
      $this->redirect(array('action' => 'index','city'=>$this->data['Venue']['city_id'])); 
     } else { 
      $this->Session->setFlash('The venue could not be saved. Please, try again.','failure'); 
     } 
    } 
+0

是否可以發佈您的控制器的$ this->數據?我不喜歡['Category'] ['Category']的外觀! – Leo

+0

顯示save()的代碼 –

+0

我已經添加了這些位,謝謝。據我所知,['Category'] ['Category']是Cake如何處理HABTM關聯?在視圖中,我只是使用$ form-> input('Category'); – Will

回答

0

也許一個愚蠢的問題,但你控制器$數據的內容傳遞給模型,當你調用save()方法 ?

$this->Venue->save($this->data) 
+0

不是一個愚蠢的問題,但是我確實通過了上面的數據。謝謝 – Will

+0

好的:-)然後我會用我最喜歡的編輯器來運行XDEBUG的動作,在調用save()之前放一個斷點,然後一步一步地找到這個數組被修改的位置。 – nIcO

+0

不幸的是,我正在共享主機環境中進行遠程開發,所以我無法安裝任何東西 – Will

0

您是否試圖將條目保存到類別表中?如果是這樣,您可以使用$this->Venue->saveAll($this->data)而不是save()。如果你只是想保存的地點數據,只是把它傳遞到save()而不是整個$this->data像這樣:$this->Venue->save($this->data['Venue']);

+0

感謝Brian,我保存了該場地和各種類別之間的關係,而不是將條目添加到類別表中。 – Will

1

我想我找到了一個解決方案,這一點,但我真的不能確定這是否應被視爲一個「好「解決方案。 我在保存前備份請求數據,然後在失敗時恢復。

$temp = $this->request->data; 

if ($this->Post->save($this->request->data)) { 

}else{ 
$this->request->data = $temp; 
}