Magento:我怎样才能有一个“调试标志”?在我的 Magento 扩展中?
我想在我正在开发的 Magento 扩展中添加一个调试标志。我希望在开发时将其设置为 true,并且当我向用户发布扩展时将其删除(默认为 false)。实现这一点的最佳方法是什么?
首先想到的是将此标志默认为 false 并在我的 app/etc/local.xml 文件中将其设置为 true。但是我怎样才能在 local.xml 中引入一个新的 XML 节点,并让 Magento 基础设施为我解析 if 并使其可用于我的 PHP 代码呢?还有其他更简单的方法吗?
I'd like to have a debug flag in the Magento extension that I'm developing. I'd like to have it set to true when I develop and when I release the extension to users have it removed (defaulting to false). What is the best way to implement this?
The first thing that comes to mind is to have this flag default to false and set it to true in my app/etc/local.xml file. But how can I introduce a new XML node into local.xml and have the Magento infrastructure parse if for me and make it available to my PHP code? Are there other, easier approaches to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过管理面板对其进行配置,并将其默认设置为 false。如果它在代码中,用户无论如何都可以切换它,所以您也可以将其放在设置面板的开发人员部分中。
Make it configurable through the admin panel, and set it to false by default. If it's in the code a user could toggle it anyway, so you may as well put it in the developer section of the settings panel.
Magento ECG 在 Magento 论坛中给了我一个很好的解决方案: http://www.magentocommerce.com/ boards/viewthread/226496/
引用它们:
我要做的就是把同样的内容放在我的 local.xml 文件中的 XML 块。这样它只会在我的开发机器上启动,并且不会与我的 Magento 扩展一起发布(扩展自己的 config.xml 也是如此)
Magento ECG gave me a good solution in the Magento forums: http://www.magentocommerce.com/boards/viewthread/226496/
Quoting them:
And what I'm going to do is put the same XML block in my local.xml file. That way it only kicks in on my development machine and does not get published with my Magento extension (as does the extension's own config.xml)
为此,我将使用 Magento 的
admin/system/config
。添加适当的
etc/system.xml
到您的模块,例如:如果
mymodule
部分之前不存在,您还需要最初定义模块的访问控制(必须放入模块的etc/config.xml
中):来通过 Magento 后端更改定义的调试标志
现在管理员可以通过选择
System -> 。配置
-我的模块
-我的组
-调试
-是|否
获取当前值您可以以编程方式使用调试标志:
I would use the
admin/system/config
of Magento for this.Add an appropriate
etc/system.xml
to your module, e.g.:If the section
mymodule
didn't already exist before, you also need to define access control for the module initially (must be put intoetc/config.xml
of your module):Now admins can change the defined debug flag thru the Magento backend by selecting
System -> Configuration
-My Module
-My Group
-Debug
-Yes|No
To get the current value of your debug flag programmatically you can use: