Я использую Joomla Framework для создания компонента, отображающего параметры из таблицы MySQL.
Поскольку каждая опция имеет множество различных параметров, они задаются как массивы json в поле custparams .
Эта функция извлекает эти пользовательские параметры из каждой опции на основе идентификатора опции.
Данные JSON декодируются и записываются в stdObject:
$_oparams=null;
function _custParamsOpt($pid)
{
$query='SELECT custparams FROM #__mycomponent_options'
.' WHERE id = '.(int)$pid;
$this->_db->setQuery( $query);
$paramdata=$this->_db->loadResult();
if (!empty($paramdata))
{
$custom=json_decode($paramdata);
foreach ($custom as $custom_params)
{
if ($custom_params->pkey=='elemvert') $this->_oparams->elemvert=$custom_params->pvalue;
if ($custom_params->pkey=='elemhor') $this->_oparams->elemhor=$custom_params->pvalue;
if ($custom_params->pkey=='minwidth') $this->_oparams->minwidth=$custom_params->pvalue;
if ($custom_params->pkey=='maxwidth') $this->_oparams->maxwidth=$custom_params->pvalue;
if ($custom_params->pkey=='minheight') $this->_oparams->minheight=$custom_params->pvalue;
if ($custom_params->pkey=='maxheight') $this->_oparams->maxheight=$custom_params->pvalue;
}
return true;
} else {
return false;
}
}
Можно ли записать эти данные как:
$this->_oparams->$pkey=$custom_params->pvalue;
чтобы я не мог перечислить все параметры?
В коде позже я проверяю параметры следующим образом:
if (!empty($this->_oparams->maxheight)) $htmlout.="\t\t\t\t<input type=\"hidden\" name=\"maxheight".$rowx->id."\" id=\"maxheight".$rowx->id."\" value=\"".$this->_oparams->maxheight."\" />";