2011-12-20 53 views
16

我正在开发一个发货模块。 在system.xml我设置了一些字段为backend_encrypted。这里是节点:在magento中解密/使用存储为config_backend_encrypted的配置值

<client_id translate="label"> 
    <label>Client ID</label> 
    <frontend_type>obscure</frontend_type> 
    <backend_model>adminhtml/system_config_backend_encrypted</backend_model> 
    <sort_order>10</sort_order> 
    <show_in_default>1</show_in_default> 
    <show_in_website>1</show_in_website> 
    <show_in_store>0</show_in_store> 
</client_id> 

我需要用价值卷曲传递到航运API,但是,当我尝试使用$this->getConfigData('client_id');找回它,它出来的加密。

我在寻找其他模块,我发现存储的值相同但不知何故,他们设法获得正确的值。

任何想法如何得到它?

回答

21

只需使用Mage::helper('core')->decrypt($this->getConfigData('client_id'));

+0

作品,谢谢。但为什么我没有看到任何其他模块解密的参考?如果你能帮忙,我错误地使用它,它不应该在哪里? – Ovidiu 2011-12-20 14:39:39

+0

你一切正常。如果您将搜索Magento代码进行“解密”,您将获得大量参考资料。 – 2011-12-20 14:44:55

+0

再次感谢Laurent。 – Ovidiu 2011-12-20 14:51:46

23

为了使用$this->getConfigData('client_id');无需手动解密它,你需要通过添加<client_id backend_model="adminhtml/system_config_backend_encrypted" />更新您的config.xml文件,见下面的例子

在你的config.xml

... 
    <default> 
     <carriers> 
      <magepal> 
       ...... 
       <client_id backend_model="adminhtml/system_config_backend_encrypted" /> 
      </magepal> 
     </carriers> 
    </default> 
</config> 
+0

添加这将透明地解密配置值,我想在10个案例中有9个是实际需要的。 尽管蒂姆的解决方案有效,但我认为这是更正确的答案。 – nnevala 2013-06-27 22:34:47

+0

^^虽然接受的答案“有效”,但这绝对确实看起来更“正确”。 – 2015-01-08 17:06:56

相关问题