Skip to content

Instantly share code, notes, and snippets.

@neohunter
Created September 26, 2012 19:19
Show Gist options
  • Save neohunter/3789979 to your computer and use it in GitHub Desktop.
Save neohunter/3789979 to your computer and use it in GitHub Desktop.
Setting model
<?php
App::uses('AppModel', 'Model');
/**
* Setting Model
*
*/
class Setting extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'key';
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'key' => array(
'notempty' => array(
'rule' => array('notempty')
),
),
'value' => array(
'notempty' => array(
'rule' => array('notempty')
),
),
);
// currently used only on users::close
private static $instance;
function &getInstance() {
if (empty(self::$instance))
self::$instance = ClassRegistry::init('Setting');
return self::$instance;
}
static function get($key){
return self::getInstance()->field('value', compact('key'));
}
static function setField($key, $value){
return self::getInstance()->updateAll(compact('value'), compact('key'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment