什么是getConfigData?
What is getConfigData?
什么是 getConfigData?以及 Magento 中 getConfigData 和 getStoreConfigData 之间的区别。
$this->getConfigData('shippingspecificcountry', $store_id);
我尝试使用我当前的商店 ID 和 0,两者都给出空数组。
谁能解释一下上面的方法
你的问题可以使用更多的上下文——缺少那个。
Mage::getStoreConfig
方法是全局 Mage
class 上的静态方法,并提供对存储在 Magento 配置树中的配置值的访问。 Magento 的配置树由
创建
- 正在加载
app/etc/*.xml
中的所有 XML 个文件
- 正在从 `app/etc/modules/*.xml' 加载所有 XML 文件
- 合并活动模块中的所有
config.xml
文件
- 合并
core_config_data
中设置的任何值(通过管理员中的 System -> Configuration
)
因为 Magento 的配置太大,许多模块开发人员添加了像 getConfigData
或 getConfig
这样的方法来使获取特定配置值变得容易。例如,考虑这个过度简化的例子
Mage::getStoreConfig('foo/baz/bar')
对比
$this->getConfig('bar');
....
public function getConfigData($key)
{
return Mage::getStoreConfig('foo/baz/' . $bar);
}
第二个允许客户端程序员更简洁的代码。
您可以在 Magento 的 various shipping carriers
的基础 class 中看到这方面的示例
public function getConfigData($field)
{
if (empty($this->_code)) {
return false;
}
$path = 'carriers/'.$this->_code.'/'.$field;
return Mage::getStoreConfig($path, $this->getStore());
}
这里的getConfigData
方法会自动在carriers
节点中查找配置key——使用carrier的_code
作为子节点,并检查实例化的carrier对象获取商店代码。
getConfigData
方法的行为会因您使用的 class/object 不同而有所不同,但希望这足以让您指向正确的方向。
什么是 getConfigData?以及 Magento 中 getConfigData 和 getStoreConfigData 之间的区别。
$this->getConfigData('shippingspecificcountry', $store_id);
我尝试使用我当前的商店 ID 和 0,两者都给出空数组。
谁能解释一下上面的方法
你的问题可以使用更多的上下文——缺少那个。
Mage::getStoreConfig
方法是全局 Mage
class 上的静态方法,并提供对存储在 Magento 配置树中的配置值的访问。 Magento 的配置树由
- 正在加载
app/etc/*.xml
中的所有 XML 个文件
- 正在从 `app/etc/modules/*.xml' 加载所有 XML 文件
- 合并活动模块中的所有
config.xml
文件 - 合并
core_config_data
中设置的任何值(通过管理员中的System -> Configuration
)
因为 Magento 的配置太大,许多模块开发人员添加了像 getConfigData
或 getConfig
这样的方法来使获取特定配置值变得容易。例如,考虑这个过度简化的例子
Mage::getStoreConfig('foo/baz/bar')
对比
$this->getConfig('bar');
....
public function getConfigData($key)
{
return Mage::getStoreConfig('foo/baz/' . $bar);
}
第二个允许客户端程序员更简洁的代码。
您可以在 Magento 的 various shipping carriers
的基础 class 中看到这方面的示例public function getConfigData($field)
{
if (empty($this->_code)) {
return false;
}
$path = 'carriers/'.$this->_code.'/'.$field;
return Mage::getStoreConfig($path, $this->getStore());
}
这里的getConfigData
方法会自动在carriers
节点中查找配置key——使用carrier的_code
作为子节点,并检查实例化的carrier对象获取商店代码。
getConfigData
方法的行为会因您使用的 class/object 不同而有所不同,但希望这足以让您指向正确的方向。