Hi
I am checking the VmConfig::get('value', 'default');
Though even when the config value is empty the default is ignored.
Looking at the code, it justifies that. The default is taken into account only when the setting does not exist, ignoring the empty inputs.
static function get($key, $default='',$allow_load=FALSE)
{
$value = '';
if ($key) {
if (empty(self::$_jpConfig->_params) && $allow_load) {
self::loadConfig();
}
if (!empty(self::$_jpConfig->_params)) {
if(array_key_exists($key,self::$_jpConfig->_params) && isset(self::$_jpConfig->_params[$key])){
$value = self::$_jpConfig->_params[$key];
} else {
$value = $default;
}
} else {
$value = $default;
}
} else {
$app = JFactory::getApplication();
$app -> enqueueMessage('VmConfig get, empty key given');
}
return $value;
}
Have you read correctly?
if(array_key_exists($key,self::$_jpConfig->_params) && isset(self::$_jpConfig->_params[$key])){
$value = self::$_jpConfig->_params[$key];
} else {
$value = $default;
}
isset(self::$_jpConfig->_params[$key]) mean if not exist value and not if empty $value
So $default is loaded if $key do not exist.
Have you do a test ?
Have you read my post?
This is exactly the bug i reported.
It's same as Joomla input.
If the value is set, default is not used.
so
if(array_key_exists($key,self::$_jpConfig->_params) && isset(self::$_jpConfig->_params[$key])){ return the
$value in all case if the
$key exist
Else it return
$defaultIt's why i have ask
QuoteHave you do a test ?
Balai, a lot configs use empty String or 0. It is completly correct that way.
I think 0 is acceptable, but an empty field is not a value.
Also the ideal would be to have also some data validation like the inputs/requests.
VmConfig::get ('value', 'default', 'type');
*type > optional (defaults to string)
Accepting empty or invalid values, renders the default param almost useless.
This could generate problems to scripts using these values, since it will pass non expected values to them.
For example yesterday i confronted an issue, where a i could not get the proper image's filename, because the thumbnail's length setting was empty or a space.
As you know the thumbnails have this format: name_lengthxwidth.png
Hence i was getting an invalid filename (missing the length part). Instead i was expecting to read the default value that was there exactly for that.
VmConfig::get ('value', 'default', 'type');
Can be done using : (type)VmConfig::get ('value', 'default');
Where type is a valid PHP type eg. Int, String, Bool, Array ...
Balai, the empty value is the common value for "use global"! That is the reason you have "is set" and "is empty"
http://php.net/manual/en/function.isset.php and http://php.net/manual/en/function.empty.php