本文介紹了在 CakePHP 中提交當前時間戳的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
直接在 INSERT
或 UPDATE
上提交當前時間戳的方法是什么?如果我運行的是常規 SQL,我會在提交時使用函數 NOW()
來處理特定的 SQL 字段.我將如何使用 CakePHP 做到這一點?
What is the method to submit a current timestamp directly on an INSERT
or an UPDATE
? If I were running regular SQL, I would use the function NOW()
for the specific SQL field on submission. How would I do that with CakePHP?
$this->Model->save($this->data)
推薦答案
在 CakePHP 中,您可以包含使用 DboSource::expression
未轉義的 NOW()
函數
In CakePHP, you can include the NOW()
function unescaped by using DboSource::expression
$this->data['SomeModel']['your_datetime_field'] = DboSource::expression('NOW()');
$this->Model->save($this->data);
這是在您的保存中包含 MySQL 函數的首選方式.
This is the preferred way of including MySQL functions in your saves.
http://api.cakephp.org/2.3/class-DboSource.html#_表達式
這篇關于在 CakePHP 中提交當前時間戳的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!