Take it just as an example:
class DateFormatBehavior extends ModelBehavior {
public function setup($Model, $config = array()) {
$defaults = array('format' => 'c');
$alias = $this->_getAlias($Model);
$this->settings[$alias] = array_merge($defaults, $config);
}
public function prettyDate($Model, $timestamp) {
$alias = $this->_getAlias($Model);
return date($this->settings[$alias], $timestamp);
}
protected function _getAlias($Model) {
return isset($Model->alias) ? $Model->alias : 'Dummy';
}
}
App::import('Behavior', 'DateFormat');
class DateFormatComponent extends DateFormatBehavior {
public function initialize($Controller, $settings = array()) {
$this->setup(null, $settings);
}
}
App::import('Behavior', 'DateFormat');
class DateFormatHelper extends DateFormatBehavior {
public function __construct($settings = array()) {
parent::__construct();
$this->setup(null, $settings);
}
}
// in model
public $actsAs = array('DateFormat' => array('format' => 'r'));
$this->prettyDate(time());
//in controller
public $components = array('DateFormat' => array('format' => 'r'));
public $helpers = array('DateFormat' => array('format' => 'r'));
$this->prettyDate(null, time());
Technically, you do not need above component - use behavior method
through model.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php