Properly read and write settings via the settings helper
This commit is contained in:
parent
af58f924b1
commit
110e5ec17d
1 changed files with 18 additions and 6 deletions
|
@ -38,6 +38,8 @@ if ( ! function_exists('setting'))
|
||||||
/** @var EA_Controller $CI */
|
/** @var EA_Controller $CI */
|
||||||
$CI = &get_instance();
|
$CI = &get_instance();
|
||||||
|
|
||||||
|
$CI->load->model('settings_model');
|
||||||
|
|
||||||
if (empty($key))
|
if (empty($key))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
||||||
|
@ -45,16 +47,26 @@ if ( ! function_exists('setting'))
|
||||||
|
|
||||||
if (is_array($key))
|
if (is_array($key))
|
||||||
{
|
{
|
||||||
foreach ($key as $item => $value)
|
foreach ($key as $name => $value)
|
||||||
{
|
{
|
||||||
$CI->session->set_userdata($item, $value);
|
$setting = $CI->settings_model->query()->where('name', $name)->get()->row_array();
|
||||||
|
|
||||||
|
if (empty($setting))
|
||||||
|
{
|
||||||
|
$setting = [
|
||||||
|
'name' => $name,
|
||||||
|
'value' => $value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$CI->settings_model->save($setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $CI->session->userdata($key);
|
$setting = $CI->settings_model->query()->where('name', $key)->get()->row_array();
|
||||||
|
|
||||||
return $value ?? $default;
|
return $setting['value'] ?? $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue