cakephp3

cakephp3 modified のみ変更 touch

More than 1 year has passed since last update.

cakephp3 で modifedのみ変更する場合。

$this->addBehavior('Timestamp', [
'events' => [
'Model.beforeSave' => [
'created' => 'new',
'modified' => 'always'
]
]
]);

// use Cake\ORM\TableRegistry;
        $this->Users = TableRegistry::get('Users');

        $valid = $this->Users->get(1859);//ユーザーID
        $this->Users->touch($valid,'Model.beforeSave');
        $this->Users->save($valid);

これで modified のみ変更することができます。