It’s so easy to implement params, that you need a simple table, Gii and 5 minutes to add a few methods to the model for ease of use. See under the spoiler. I don’t think that there should be a default implementation, because it’s very easy and most of us do that to our liking (some will add more fields, others will chop it down to keyword + value and make keyword unique. I for once sometimes use multiple records with the same keyword and different values).
[spoiler]
[sql]CREATE TABLE param
(
`id` int unsigned not null auto_increment,
`description` varchar(255) not null,
`keyword` varchar(128) not null,
`value` carchar(255) not null,
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;[/sql]
class Param extends CActiveRecord {
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return 'param';
}
public function rules() {
return array(
array('description, value, keyword', 'required'),
array('description, value', 'length', 'max'=>255),
array('keyword', 'length', 'max'=>128),
array('id, description, value, keyword', 'safe', 'on'=>'search'),
);
}
public function relations() {
return array(
);
}
public function attributeLabels() {
return array(
'id' => Yii::t('app', 'ID'),
'description' => Yii::t('app', 'Description'),
'value' => Yii::t('app', 'Value'),
'keyword' => Yii::t('app', 'Keyword'),
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id, true);
$criteria->compare('description', $this->description, true);
$criteria->compare('value', $this->value, true);
$criteria->compare('keyword', $this->keyword, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 50,
),
'sort' => array(
'defaultOrder' => 'keyword',
),
));
}
/**
* @static
* @param $name
* @param bool $multiple If true, returns array, else string
* @return string|array
*/
public static function getValue($name, $multiple = false)
{
static $params = array();
if (!array_key_exists($name, $params)) {
/** @var $model Param */
$model = $multiple
? self::model()->findAllByAttributes(array('keyword' => $name))
: self::model()->findByAttributes(array('keyword' => $name));
if (is_null($model)) {
$params[$name] = null;
} else {
if ($multiple) {
foreach ($model as $param) {
$params[$name][] = $param->value;
}
} else {
$params[$name] = $model->value;
}
}
unset($model);
}
return $params[$name];
}
/**
* @param string $keyword
* @param mixed $value
* @param string $description
* @return bool
*/
public static function setValue($keyword, $value, $description = '[system]') {
$model = self::model()->findByAttributes(array('keyword' => $keyword));
if (!$model) {
$model = new Param();
}
$model->keyword = $keyword;
$model->value = $value;
$model->description = $description;
if ($model->save()) {
return true;
} else {
return false;
}
}
}
[/spoiler]