2012-05-25 158 views
0

我試圖創建一個社交網絡類型的網站,用戶可以發送/接收朋友請求。在我們當前的系統中,當用戶發送一個請求時,所需信息的一半被存儲在數據庫中,然後當用戶接受其餘的信息時,剩餘的信息被輸入。CakePHP HABTM關係問題

的relationships_users表ID,partyone,partytwo,expirydate,活性

具有問題IM是一旦用戶接受的請求,並且在到期日期,把其插入一個新列 - 並不在列與該用戶

here is my add function 

    if($this->request->is('post')){ 
    $this->Relationship->create(); 
    if ($this->Relationship->save($this->request->data)) 
    { 
     $this->Session->setFlash('The relationship has been saved'); 

    } 
    else { $this->Session->setFlash('The relationship could not be saved. Please, try again.'); } 
    } 

    } 

here is my approve function 

if($this->request->is('post')){ 
     $this->Relationship->create(); 
     $this->Relationship->save($this->request->data); 
     $this->Session->setFlash('The information has been saved');} 
     else{$this->Session->setFlash('The information couldnt be saved');} 

IM假設我已經錯過了一些簡單的代碼,任何幫助,將不勝感激 其插入一個新列 - 不與用戶的關係*列

回答

0

您的文章沒有在整個的問題,但我明白,你應該按照下述一些步驟:

  • 當信息的上半年保存在Relationship表,那麼你必須獲得該條目的id你可以得到類似如下:

    $this->Relationship->save($this->request->data);

    $lastId = $this->Relationship->id; // will gives you id of first half info saved

  • 然後,你必須嵌入該$lastId與信息的其餘部分,即請求確認後的後半部分。如果您可以將該ID嵌入到$this->request->data內的後半部分信息中,則$this->Relationship->save($this->request->data)將更新之前保存的行。在這種情況下,你不需要$this->Relationship->create();

    根據cakePHP,如果其中的任何數據包含id,則不是創建新行並保存,而是更新具有該id的對應行。