【发布时间】:2016-02-02 09:34:15
【问题描述】:
今天我发现自己在 CakePHP 中有一个奇怪的行为。
我想要存档的是更新数据库中的列以反映上次查看的日期。当使用与标准时间戳事件(如创建、修改等)不同的列时,可以使用“touch()”来完成此操作。
- 我想要什么:我想在 页面。
- 发生了什么:当前日期时间戳显示在 页面。
我在这里看到的奇怪行为是:在我将实体设置为视图变量并更新触摸“上次查看”日期后,设置的视图变量中的数据反映了这种变化。
设置实体到视图的代码:
// get the request entity with the ID:
$request = $this->Requests->get($request_id);
// set the entity to the $request view variable:
$this->set('request', $request);
// finally update the last viewed date (database column name: 'opened'):
$this->Requests->touch($request, 'Requests.opened');
$this->Requests->save($request);
为什么$request视图变量会反映设置变量后执行的触摸变化?
【问题讨论】:
标签: php cakephp view timestamp entity