Skip to content

Instantly share code, notes, and snippets.

@hugodias
Created May 30, 2014 14:27
Show Gist options
  • Save hugodias/f5e99c8bd0f04bbbd550 to your computer and use it in GitHub Desktop.
Save hugodias/f5e99c8bd0f04bbbd550 to your computer and use it in GitHub Desktop.
Converting all created & modified fields date to BR format in CakePHP for all models
<?php
/**
* Application model for Cake.
*
* This file is application-wide model file. You can put all
* application-wide model-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.Model
* @since CakePHP(tm) v 0.2.9
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Model', 'Model');
/**
* Application model for Cake.
*
* Add your application-wide methods in the class below, your models
* will inherit them.
*
* @package app.Model
*/
App::uses('CakeTime', 'Utility');
class AppModel extends Model
{
public function afterFind($results, $primary = false) {
foreach ($results as $key => $val) {
$model = key($val);
if(!empty($val[$model]['created'])){
$results[$key][$model]['created'] = $this->dateFormatAfterFind(
$val[$model]['created']
);
}
if(!empty($val[$model]['modified'])){
$results[$key][$model]['modified'] = $this->dateFormatAfterFind(
$val[$model]['modified']
);
}
}
return $results;
}
public function dateFormatAfterFind($dateString) {
return CakeTime::format($dateString, '%d/%m/%Y %H:%M');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment