Submitting current timestamp in CakePHP(在 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 中提交当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 CakePHP 中提交当前时间戳
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
