Posted By

kendsnyder on 03/30/11


Tagged

ruby cakephp


Versions (?)

Using created_at and updated_at with CakePHP


 / Published in: PHP
 

Ruby uses createdat and updatedat. Here cake will do the same thing. based on http://book.cakephp.org/view/1015/created-and-modified

  1. <?php
  2.  
  3. class AppModel extends Model {
  4.  
  5. function save($data = null, $validate = true, $fieldList = array()) {
  6. $now = date('Y-m-d H:i:s');
  7. // set created_at field before creation
  8. if (!isset($this->data[$this->name]) || !$this->data[$this->name]['id']) {
  9. $data[$this->name]['created_at'] = $now;
  10. }
  11. // set updated_at field value before each save
  12. $data[$this->name]['updated_at'] = $now;
  13. return parent::save($data, $validate, $fieldList);
  14. }
  15.  
  16. }

Report this snippet  

You need to login to post a comment.