CakePHP更新資料(轉載)

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   for   

  CakePHP中更新資料的方法包括saveField()和updateAll()兩種,其中前者用於儲存單個欄位,後者用於更新多條記錄。

  saveField(string $fieldName, string $fieldValue, $validate = false)

  saveField()在調用前需要設定模型的ID($this->ModelName->id = $id)。使用該方法時,$fieldName應該只包含欄位名,而不是模型名加欄位名。

  例如,使用saveField更新投稿日誌的標題:

$this->Post->saveField(‘title‘, ‘A New Title for a New Day‘);

  updateAll(array $fields, array $conditions)

  updateAll()將被更新的記錄用$conditions數組定義,欄位的值會按照$fields的定義進行更新。

  例如,對建立時間超過1年的成員進行確認,可能使用如下的更新語句:

$this_year = date(‘Y-m-d h:i:s‘, strtotime(‘-1 year‘));$this->Baker->updateAll(    array(‘Baker.approved‘ => true),    array(‘Baker.created <=‘ => "$this_year"));

  $fields>資料接收SQL運算式。文本資料需要手動地添加引號。

  例如,更改特定使用者的票的狀態:

$this->Ticket->updateAll(    array(‘Ticket.status‘ => "‘closed‘"),    array(‘Ticket.customer_id‘ => 453));

 

部落格聲明:

  本部落格中的所有文章,除標題中註明“轉載”字樣外,其餘所有文章均為本人原創或在查閱資料後總結完成,引用非轉載文章時請註明此聲明。—— 部落格園-pallee

CakePHP更新資料(轉載)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.