我有两个对象,以及我们的 finder 函数的工作方式(我必须调用它两次...... 1 获取配置键、值,即非多语言内容。第二次调用获取多语言内容)使它们看起来像这样:
[config] => Array
(
[cfg] => Config_Model Object
(
[id] => 2
[key] => system.default.main_color
[value] => #FF7C11
[deleted] => 0
)
[help] => Config_Model Object
(
[id] =>
[key] =>
[value] =>
[id_config] => 2
[name] => Hauptfarbe
[help] => Die Hauptfarbe Ihres CIs. Der Adminbereich erscheint in dieser Farbe.
[id_lang] => 1
)
)
我想将这两个对象合二为一。获取这些内容的代码如下所示:
public static function get($key)
{
$config['cfg'] = self::find(array('key' => $key), TRUE);
$config['help'] = self::findInTable(array(
'id_lang' => Language_Model::getDefaultLanguage(),
'id_config' => $config['cfg']->getId()
), self::dbTranslationTable, TRUE);
return $config;
// return (object) array_merge((array) $config['cfg'], (array) $config['help']);
}
您可以通过注释的返回命令判断我尝试使用 array_merge()。问题在于,[help] 中的空属性覆盖了 [cfg] 中的属性,因此它们再次为空:
[config] => stdClass Object
(
[id] =>
[key] =>
[value] =>
[deleted] => 0
[id_config] => 2
[name] => Hauptfarbe
[help] => Die Hauptfarbe Ihres CIs. Der Adminbereich erscheint in dieser Farbe.
[id_lang] => 1
)
而它应该看起来像这样:
[config] => stdClass Object
(
[id] => 2
[key] => system.defalult.main_color
[value] => #FF7C11
[deleted] => 0
[id_config] => 2
[name] => Hauptfarbe
[help] => Die Hauptfarbe Ihres CIs. Der Adminbereich erscheint in dieser Farbe.
[id_lang] => 1
)
如果您需要更多信息,请告诉我。