Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting current timestamp in 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)
like image 263
macha Avatar asked Sep 29 '10 15:09

macha


1 Answers

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);

This is the preferred way of including MySQL functions in your saves.

http://api.cakephp.org/2.3/class-DboSource.html#_expression

like image 176
webbiedave Avatar answered Sep 24 '22 20:09

webbiedave