我有一个模块。这需要管理员配置。我不知道如何在admin-> system->配置中创建菜单以及如何将项目添加到该自定义菜单.... 请帮帮我....
答案 0 :(得分:1)
它包含4个文件,用于为模块添加新的配置菜单。如果您的模块已经有一个辅助类Data.php,那么只需要两个xml文件。帮助程序类Data.php可以为空,只需在管理面板中加载新的菜单配置即可。 最重要的两个xml文件是模块的etc文件夹中的 adminhtml.xml 和 system.xml 文件。
示例adminhtml.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<helloworld_setting>
<title>Hello World</title>
</helloworld_setting>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
示例system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<tabs>
<helloworld translate="label" module="helloworld">
<label>Hello World</label>
<sort_order>99999</sort_order>
</helloworld>
</tabs>
<sections>
<helloworld_setting translate="label" module="helloworld">
<label>Settings</label>
<tab>helloworld</tab>
<frontend_type>text</frontend_type>
<sort_order>99</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<greeting_settings translate="label">
<label>Greeting Settings</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>
<fields>
<enabled translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enabled>
<greeting translate="label,comment">
<label>Greeting</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Greeting text.</comment>
</greeting>
</fields>
</greeting_settings>
</groups>
</helloworld_setting>
</sections>
</config>
检索您在配置菜单中设置的值
//sectionName/groupName/fieldName
echo Mage::getStoreConfig('helloworld_setting/greeting_settings/enabled');
echo Mage::getStoreConfig('helloworld_setting/greeting_settings/greeting');
如果有任何问题,请确保在代码更改后清除缓存,并仔细检查xml文件中是否存在拼写错误。