1
在elance.com上有一個關於getStoreConfig函數的問題。認證考試中很可能存在這樣的問題。Magento getStoreConfig任務。在elance.com上
Which one of the following xpaths can be read using Mage::getStoreConfig('some/value')?
Answers:
• default/some/value
• some/value
• some/value/default
• global/default/some/value
• stores/some/value
該服務告訴正確答案是'stores/some/value'。但如果放眼到代碼中,我們將看到:
public static function getStoreConfig($path, $store = null)
{
return self::app()->getStore($store)->getConfig($path);
}
public function getConfig($path)
{
if (isset($this->_configCache[$path])) {
return $this->_configCache[$path];
}
$config = Mage::getConfig();
$fullPath = 'stores/' . $this->getCode() . '/' . $path;
$data = $config->getNode($fullPath);
if (!$data && !Mage::isInstalled()) {
$data = $config->getNode('default/' . $path);
}
if (!$data) {
return null;
}
return $this->_processConfigValue($fullPath, $path, $data);
}
這意味着,正確的答案是:
$fullPath = 'stores/' . $this->getCode() . '/' . $path;
(stores/default{or some another store}/some/value)
或
$data = $config->getNode('default/' . $path);
(default/some/value)
如果我們調試這一點,我們可以看到,商店只有管理員和商店名稱子節點。有誰可以澄清這一點?我錯過了什麼嗎?