在CakePHP中提交当前时间戳 [英] Submitting current timestamp in CakePHP
本文介绍了在CakePHP中提交当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
直接在 INSERT
或 UPDATE
上提交当前时间戳的方法是什么?如果我正在运行常规SQL,我将使用函数 NOW()
提交时的特定SQL字段。
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中,可以包括<$ c $通过使用 DboSource :: expression
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 #_expression
这篇关于在CakePHP中提交当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文