mirror of
https://github.com/janickiy/yii2-nomer
synced 2025-03-09 15:39:59 +00:00
add files to project
This commit is contained in:
commit
5cac498444
3729 changed files with 836998 additions and 0 deletions
62
models/Settings.php
Normal file
62
models/Settings.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "settings".
|
||||
*
|
||||
* @property integer $id
|
||||
* @property string $param
|
||||
* @property string $value
|
||||
*/
|
||||
class Settings extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['param', 'value'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'param' => 'Param',
|
||||
'value' => 'Value',
|
||||
];
|
||||
}
|
||||
|
||||
public static function get($param, $defaultValue = null) {
|
||||
$p = self::find()->where(["param" => $param])->one();
|
||||
if(is_null($p)) return $defaultValue;
|
||||
return ArrayHelper::getValue($p, "value");
|
||||
}
|
||||
|
||||
public static function set($param, $value) {
|
||||
$p = self::find()->where(["param" => $param])->one();
|
||||
if(is_null($p)) {
|
||||
$p = new self;
|
||||
$p->param = $param;
|
||||
}
|
||||
$p->value = $value;
|
||||
$p->save();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue