Return to Snippet

Revision: 43752
at March 30, 2011 10:16 by kendsnyder


Initial Code
<?php

class AppModel extends Model {

	function save($data = null, $validate = true, $fieldList = array()) {
		$now = date('Y-m-d H:i:s');
		// set created_at field before creation
		if (!isset($this->data[$this->name]) || !$this->data[$this->name]['id']) {
			$data[$this->name]['created_at'] = $now;
		}
		// set updated_at field value before each save
		$data[$this->name]['updated_at'] = $now;
		return parent::save($data, $validate, $fieldList);
	}

}

Initial URL


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

Initial Title
Using created_at and updated_at with CakePHP

Initial Tags
ruby, cakephp

Initial Language
PHP