向 Magento 系统管理员添加选项
Add option to Magento system admin
我想在位于系统>配置>设计>页眉中的页眉块中添加一个文本框,如下图中的位置。
我知道这必须在 xml 中完成,但我不确定在哪里。另外,我将如何在 phtml 文件中显示它?
首先在 system.xml 文件中添加一个字段,该文件位于
app/code/core/Mage/Page/etc/system.xml,在 header 部分下
<header translate="label">
..........
<welcome_massage translate="label">
<label>Welcome Massage</label>
<frontend_type>text</frontend_type>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</welcome_massage>
</fields>
</header>
然后在header块中添加一个方法,app/code/core/Mage/Page/Block/Html/Header.php
public function getWelcomeMassage()
{
return $this->_data['welcome_massage'] = Mage::getStoreConfig('design/header/welcome_massage') ;
}
上次在 header.phtml 文件中调用此方法,就像那样
<?php echo $this->getWelcomeMassage() ?>
Note : You see that I have code in core files. You should rewrite the
core files.
在 code/core/Mage/Page/etc/system.xml
中,您将找到 Magento 读取以显示这些字段的配置,例如 "Small Logo Image src" 是一个名为 logo_src_small
的字段。需要的是一个模块,它将告诉 Magento:
header下管理面板中的额外字段。
<config>
<sections>
<design>
<groups>
<header>
<fields>
<new_field translate="label">
<label>New Field</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</new_field>
</fields>
</header>
</groups>
</design>
</section>
</config>
重写块 class code/core/Mage/Page/Block/Html/Header.php
以便您可以添加将公开新字段的方法。
- 在 app/design/frontend/{Package}/{Theme}/template/page/html/header.phtml 中,您可以轻松调用
$this->getNewField()
,其中 getNewField() 是您在 class 我们在第 2 点中覆盖了。
几个帮助您开始的链接:
- http://excellencemagentoblog.com/blog/2011/09/22/magento-part8-series-systemxml/
- http://www.ecomdev.org/2010/10/27/custom-configuration-fields-in-magento.html
- http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/
- https://magento.stackexchange.com/questions/78175/add-custom-field-in-admin-system-configuration-sales
我想在位于系统>配置>设计>页眉中的页眉块中添加一个文本框,如下图中的位置。
我知道这必须在 xml 中完成,但我不确定在哪里。另外,我将如何在 phtml 文件中显示它?
首先在 system.xml 文件中添加一个字段,该文件位于
app/code/core/Mage/Page/etc/system.xml,在 header 部分下
<header translate="label">
..........
<welcome_massage translate="label">
<label>Welcome Massage</label>
<frontend_type>text</frontend_type>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</welcome_massage>
</fields>
</header>
然后在header块中添加一个方法,app/code/core/Mage/Page/Block/Html/Header.php
public function getWelcomeMassage()
{
return $this->_data['welcome_massage'] = Mage::getStoreConfig('design/header/welcome_massage') ;
}
上次在 header.phtml 文件中调用此方法,就像那样
<?php echo $this->getWelcomeMassage() ?>
Note : You see that I have code in core files. You should rewrite the core files.
在 code/core/Mage/Page/etc/system.xml
中,您将找到 Magento 读取以显示这些字段的配置,例如 "Small Logo Image src" 是一个名为 logo_src_small
的字段。需要的是一个模块,它将告诉 Magento:
header下管理面板中的额外字段。
<config> <sections> <design> <groups> <header> <fields> <new_field translate="label"> <label>New Field</label> <frontend_type>text</frontend_type> <sort_order>1</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </new_field> </fields> </header> </groups> </design> </section> </config>
重写块 class
code/core/Mage/Page/Block/Html/Header.php
以便您可以添加将公开新字段的方法。- 在 app/design/frontend/{Package}/{Theme}/template/page/html/header.phtml 中,您可以轻松调用
$this->getNewField()
,其中 getNewField() 是您在 class 我们在第 2 点中覆盖了。
几个帮助您开始的链接:
- http://excellencemagentoblog.com/blog/2011/09/22/magento-part8-series-systemxml/
- http://www.ecomdev.org/2010/10/27/custom-configuration-fields-in-magento.html
- http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/
- https://magento.stackexchange.com/questions/78175/add-custom-field-in-admin-system-configuration-sales