深入理解Magento – 第十一章 – Magento的默认系统配置值

2,223次阅读
没有评论

共计 4213 个字符,预计需要花费 11 分钟才能阅读完成。

This is more of an addendum to my previous articles on the System Configuration system than an entirely new article. Go back and read up if anything’s over your head.

When you create a new System Configuration path, Magento doesn’t store a default value. This is true even for the default stock system configuration. You can confirm this by looking at the core_config_datatable.

mysql> select * from core_config_data ;
+———–+———+———-+—————————-+————+
| config_id | scope | scope_id | path | value |
+———–+———+———-+—————————-+————+

This table will only store values that have been explicitly set via the Admin Console or other programatic means. If you request the value of a System Configuration path that doesn’t have a value explicitly set, Magento will check the global config tree for a default value. Although not required, it’s a good idea to set a default value for your custom configuration variables. It’s simple enough to do, and will ensure nothing unexpected happens when a blank value is retrieved for your config variables.

Setting up Default Values

As previously mentioned, default values are stored in the global config tree. This is slightly counter-intuitive, as one might expect the values to be stored in the same system.xmlthat the paths themselves are configured in. As with many things Magento, the old

Ours is not to question why, ours is but to do or die

serves as your best bet for coping with this. If that’s not good enough, try thinking of the global config as a place to store commonly used values, and system.xml as the place you configure a UI for changing those values. Hand holding out of the way, let’s get to it. In your module’s config.xml, add a top level section named <default/>.

1 <!-- File: app/code/local/Packagename/Modulename/etc/config.xml -->
2 <config>
3  <!-- ... -->
4  <default>
5  </default>
6  <!-- ... -->
7 </config>

This is the top-level node where you’ll be storing your default values. Next, take your configuration path, and convert it into an XML tree node. For example, if you were setting up a default value for the configuration path

design/header/welcome 

your config would look something like

01 <!-- File: app/code/local/Packagename/Modulename/etc/config.xml -->
02 <config>
03  <!-- ... -->
04  <default>
05  <design>
06  <header>
07  <welcome>Default welcome msg!</welcome>
08  </header>
09  </design>
10  </default>
11  <!-- ... -->
12 </config>

With a configuration setup like the one above, requests for

design/header/welcome 

would, with no value configured, return the text “Default welcome msg!”. This example is based on an existing configuration setting in a stock Magento install. Remember, most of Magento functionality is built using the same Module system you use to customize the system. Let’s take a look at the actual configuration of the design/header/welcomevalue.

01 <!-- File: app/code/core/Mage/Page/etc/config.xml -->
02 <default>
03  <design>
04  <headtranslate="default_description"module="page">
05  <default_title>Magento Commerce</default_title>
06  <default_description>Default Description</default_description>
07  <default_keywords>Magento, Varien, E-commerce</default_keywords>
08  <default_robots>*</default_robots>
09  <default_media_type>text/html</default_media_type>
10  <default_charset>utf-8</default_charset>
11  </head>
12  <headertranslate="welcome"module="page">
13  <logo_src>images/logo.gif</logo_src>
14  <logo_alt>Magento Commerce</logo_alt>
15  <welcome>Default welcome msg!</welcome>
16  </header>
17  <footertranslate="copyright"module="page">
18  <copyright>&amp;copy; 2008 Magento Demo Store. All Rights Reserved.</copyright>
19  </footer>
20  </design>
21 </default>

This is the full default configuration for the

design/* 

configuration hierarchy. One thing different from our previous examples is the optional translation attributes.

1 <headertranslate="welcome" module="page">

The translate and moduleattributes tell the system which nodes need to be translated, and which module’s Data Helper should be used to do the translating. In the above example that means the welcome node would be translated with

1 Mage::helper('page')->__(...);

Remember, if you call the helper factory without a second URI portion, Magento will default to the data helper.

1 //the same
2 Mage::helper('page')->__(...);
3 Mage::helper('page/data')->__(...);

If you wanted multiple sub-nodes to be translated, just separate the names with commas

1 <example translate="foo,baz,bar"module="page">

Wrapup

Short and sweet this week. While not necessary, it’s a good idea to set your System Configuration paths with default values. By setting a default early, you ensure that there will alwaysbe a logical value returned for the configuration path and not have to worry about jury rigging one in later, when a user may have inadvertently saved a value with an empty string.

Originally published November 28, 2010
正文完
 0
评论(没有评论)

空瓶子部落

文章搜索
推荐阅读
顾问遇见7步成诗,工程师碰到8D,难题就迎刃而解!

顾问遇见7步成诗,工程师碰到8D,难题就迎刃而解!

商业领域里,有很多解决问题的高手和方法,比如重策略的麦肯锡,提倡“七步成诗法”;重实践的丰田,提倡“八步成诗法...
做品质工程师首先必备的素质——匪气

做品质工程师首先必备的素质——匪气

做品质工程师首先必备的一个素质——匪气。这个匪气并不是土匪吃喝嫖赌、杀人越货、胡作非为的顽劣习气,而是说干品质...
工序质量控制:自检+首检+巡检内容和规则

工序质量控制:自检+首检+巡检内容和规则

*工序质量检验的目的,是利用一定的方法,对工序操作及其完成产品的质量,进行实际而及时的测定和检查。 并将所测得...
【口诀】三句话记住控制图八大判异准则

【口诀】三句话记住控制图八大判异准则

八大判异准则是SPC控制图的重要内容,通常我们都是逐一对这八种判异准则进行学习,而学过之后好像只记住了最后一条...
突破端口限制,实现域名免加端口访问家庭内网服务

突破端口限制,实现域名免加端口访问家庭内网服务

如何进一步实现只输域名访问家庭内网的服务呢?因家庭网络服务商(联通、电信、移动、长城等)都会封闭常用服务端口已...
最新文章
Free TV:全球免费电视频道 M3U 播放列表,狂揽数万 Star

Free TV:全球免费电视频道 M3U 播放列表,狂揽数万 Star

https://github.com/Free-TV/IPTV 项目简介 Free TV 是一个精心维护的开源...
群晖 Let’s Encrypt 泛域名证书自动更新

群晖 Let’s Encrypt 泛域名证书自动更新

目前acme协议版本更新,开始支持泛域名(wildcard),也就是说,可以申请一个类似*.domain.co...
可以卸载TV Box 了,这款支持「绅士模式」的影视神器你值得拥有

可以卸载TV Box 了,这款支持「绅士模式」的影视神器你值得拥有

还在为找优秀片源难、广告多、平台会员太贵而烦恼?今天给大家挖到一款真正的影视宝藏工具——小猫影视! 作为开源免...
【收藏】一次性解决TV点播/直播自由

【收藏】一次性解决TV点播/直播自由

很多时候,资源就在面前,但是我们视而不见,因为长久的安逸,已经让人失去动手的兴趣。但是每次我需要挨个切换APP...
OpenWrt 存储空间扩容的两种方案

OpenWrt 存储空间扩容的两种方案

说明:当我们通过群晖 VMM 虚拟机安装 Open­Wrt 时,默认会分配一个 10GB 的存储空间,而实际情...
热门文章
提高过程能力指数(CP/CPK)的途径

提高过程能力指数(CP/CPK)的途径

编者按:过程能力指数(CP/CPK)想必各位质量人都耳熟能详、运用自如,质量工程师之家前期也共享过数篇关于过程...
SPC控制图的八种模式分析

SPC控制图的八种模式分析

SPC控制图有八种模式,即八种判断异常的检验准则,每一种检验准则代表一种异常现象,应用SPC控制图进行过程评估...
测量高手放大招:圆跳动测量技巧总结

测量高手放大招:圆跳动测量技巧总结

01. 前言 在五金机加工厂实际的测量工作中,经常碰到要求测量两个要素的圆跳动问题, 利用不同的测量辅件及夹具...
过程能力分析(CP&cpk)

过程能力分析(CP&cpk)

引入过程能力分析的目的? 在我们现有的管理过程中,我们经常会遇到有些具体指标总是不尽人意,存在许多需要改进的地...
新能源汽车 “两会”精神宣贯会

新能源汽车 “两会”精神宣贯会

此次和大家分享新能源汽车相关政策: [embeddoc url=”https://www.ctro...
最新评论
多乐士 多乐士 通过摸索发现ssh拉取会报错,直接网页访问下载会报404错误,不知道原因;但是可以通过群晖CM注册表访问下载,其方法如下: Container Manager-注册表-设置-新增-注册表名称随便写,注册表URL填你的加速地址,勾选信任的SSL自我签署证书,登录信息不填-应用-使用你的地址,这是注册表会显示了,在搜索栏中输入映像名称,搜索结果在每一页的最后一个,你需要划到最后一个进行下载,实测可正常下载安装。 以上供网友参考。
多乐士 多乐士 还有一个比较简单的方法,只是需要一些外部工具。 1、讲损毁硬盘取出,装入外部移动硬盘 2、打开Diskgenius,定位到硬盘 3、格式化系统分区 4、重新插入硬盘 5、存储池->修复存储池即可
多乐士 多乐士 写的不错的文章
辞了老衲 辞了老衲 这个确实有帮助。
渋驀 渋驀 当然任何时候都可以用curl命令和crontab来实现动态更新DDNS的ip地址: 1、安装crontab之后为root用户创建文件/var/spool/cron/root 2、创建并配置ddnsupdate.sh,放到/usr/bin/文件下,文件内容(以he.net为例): Autodetect my IPv4/IPv6 address: IPV4:curl -4 "http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com" IPV6:curl -6 "http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com" 3、添加执行权限chomod +x /usr/bin/ddnsupdate.sh 4、编辑root用户的crontab:*/10 * * * * /usr/binddnsupdate.sh,每10分钟执行一次。好了,可以享受你的DDNS了
21410 21410 请问下载链接在那里?
madkylin madkylin 不错,不错,谢谢分享了,好东西啊 :lol:
feilung feilung 求方法
zengsuyi zengsuyi 应该挺不错的
zise zise 看看是怎么操作的。。 :oops: