【问题标题】:Magento admin menu block is not showing in configuration tab?Magento 管理菜单块未显示在配置选项卡中?
【发布时间】:2013-08-07 07:45:19
【问题描述】:

我只是 magento 扩展的新手。我想在 magento version 1.7.0.2 中创建一个名为 storeinfo 的新模块。为此,我的app/local 的文件夹结构是这样的

magento directory
  app
    code
      community
      core
      local---
            |--- New(foldername)--
                  |---Storeinfo(foldername)--
                        |-Block
                          controllers
                          etc
                          Helper
                          sql

New_Storeinfo.xml 的代码在 magentodirectory/app/etc 内部是这样的

 <?xml version="1.0"?>
<config>
  <modules>
    <New_Storeinfo>
      <active>true</active>
      <codePool>local</codePool>
    </New_Storeinfo>
  </modules>
</config>

现在目录magentodirectory/app/code/local/New/Storeinfo/etc/config.xml里面是这样的

<?xml version="1.0"?>
<config>
  <modules>
    <New_Storeinfo>
      <version>0.1.1</version>
    </New_Storeinfo>
  </modules>

  <frontend>
    <routers>
      <storeinfo>
        <use>standard</use>
        <args>
          <module>New_Storeinfo</module>
          <frontName>storeinfo</frontName>
        </args>
      </storeinfo>
    </routers>
    <layout>
      <updates>
        <storeinfo>
          <file>newstoreinfo.xml</file>
        </storeinfo>
      </updates>
    </layout>
  </frontend>

  <adminhtml>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <system>
              <children>
                <config>
                  <children>
                    <storeinfo>
                      <title>Store Map</title>
                    </storeinfo>
                  </children>
                </config>
              </children>
            </system>
          </children>
        </admin>
      </resources>
    </acl>
  </adminhtml>

  <global>
        <models>
            <storeinfo>
                <class>New_Storeinfo_Model</class>
        <resourceModel>storeinfo_mysql4</resourceModel>
            </storeinfo>
        </models>
    <resources>
            <storeinfo_setup>
                <setup>
                    <module>New_Storeinfo</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </storeinfo_setup>
            <storeinfo_write>
                <connection>
                  <use>core_write</use>
                </connection>
            </storeinfo_write>
            <storeinfo_read>
               <connection>
                <use>core_read</use>
              </connection>
            </storeinfo_read>
        </resources>
    <blocks>
            <storeinfo><class>New_Storeinfo_Block</class></storeinfo>
        </blocks>
    <helpers>
            <storeinfo>
                <class>New_Storeinfo_Helper</class>
            </storeinfo>
        </helpers>
    </global>
  <default>
        <storeinfo>
      <address>
        <enabled>1</enabled>
        <title>Our Store Address</title>
        <address>Replace this with Your Address with or without HTML code here....</address>
      </address>
      <storeinfo>
        <enabled>1</enabled>
        <title>Our Location Map</title>
        <map_location>Paste Map HTML code here...</map_location>
      </storeinfo>
    </storeinfo>
    </default>
</config>

现在目录magentodirectory/app/code/local/New/Storeinfo/etc/system.xml我的代码是这样的

<?xml version="1.0"?>
<config>
    <tabs>
        <storeinfo translate="label" module="storeinfo">
            <label>Store Map &amp; Address</label>
            <sort_order>132</sort_order>
        </storeinfo>
    </tabs>
    <sections>
        <storeinfo translate="label" module="storeinfo">
            <label>Map &amp; Address Info.</label>
            <tab>storeinfo</tab>
            <frontend_type>text</frontend_type>
            <sort_order>100</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <storeinfo translate="label">
                    <label>Settings</label>
                    <comment><![CDATA[
                        <p>
                            <div>Add Store info:</div>
                        </p>
                    ]]></comment>
                    <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>0</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </enabled>
                        <title translate="label">
                            <label>Title</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>
                        </title>
                        <map_location translate="label">
                            <label>Location Map HTML code</label>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment><![CDATA[Collect you store map html code from any of the maps code provides like <strong>Google, Yahoo..</strong>]]></comment>
                        </map_location>
                    </fields>
                </storeinfo>
                <address translate="label">
                    <label>Address</label>
                    <comment><![CDATA[
                        <p>
                            <div>Add Store Address to your Magento Store:</div>
                        </p>
                    ]]></comment>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</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>0</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </enabled>
                        <title translate="label">
                            <label>Title</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>
                        </title>
                        <address translate="label">
                            <label>Address</label>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Put you store address with or without HTML code</comment>
                        </address>
                    </fields>
                </address>
            </groups>
        </storeinfo>
    </sections>
</config>

但在所有代码之后,Storeinfo 的菜单并未显示在 magento 的管理配置选项卡中。那么有人可以告诉我这里有什么问题吗?任何帮助和建议都会非常明显。谢谢...

【问题讨论】:

  • 你去系统-->配置-->高级-->启用禁用模块输出-->检查你是否创建了模块。
  • @VIVEK-MDU 是的,模块显示在高级,但它没有显示在配置选项卡中。我已经尝试了很多次从高级选项卡打开和关闭 .. 但什么也没发生.. .
  • 你的助手文件夹中有一个名为 Data.php 的助手吗?你刷新缓存了吗?

标签: php xml magento magento-1.7


【解决方案1】:

已在magento.stackexchange.com 上回答了该问题并提供了更多详细信息。
问题出在声明 xml 文件中。标签&lt;codepool&gt; 应该是&lt;codePool&gt; - 大写P

【讨论】:

  • 我已将 更改为 大写 p 但仍然显示相同的问题...检查我更新的问题...
  • 你清除缓存了吗?我已将您的代码复制到本地 Magento 实例上,更改为 &lt;codePool&gt; 后一切正常。
【解决方案2】:

从 config.xml 中删除以下代码

<adminhtml>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <system>
              <children>
                <config>
                  <children>
                    <storeinfo>
                      <title>Store Map</title>
                    </storeinfo>
                  </children>
                </config>
              </children>
            </system>
          </children>
        </admin>
      </resources>
    </acl>
  </adminhtml>

并在 etc 文件夹中创建一个 adminhtml.xml 文件,内容如下

<?xml version="1.0"?>
<config>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <system>
              <children>
                <config>
                  <children>
                    <storeinfo>
                      <title>Store Map</title>
                    </storeinfo>
                  </children>
                </config>
              </children>
            </system>
          </children>
        </admin>
      </resources>
    </acl>
  </config>

【讨论】:

    【解决方案3】:

    我建议使用生成器来构建大多数类似的基本内容,以避免拼写错误等。

    http://www.silksoftware.com/magento-module-creator

    【讨论】:

      【解决方案4】:

      除非是拼写错误,否则您提到您的 New_Storeinfo.xml 位于:

      magentodirectory/app/etc
      


      这实际上应该位于此文件夹中:

      magentodirectory/app/etc/modules
      

      刷新缓存,现在你的模块应该出现在系统 -> 配置 -> 高级

      【讨论】:

        【解决方案5】:

        试试这个方法。它用于为 magento admin 创建一个菜单选项卡。

        根据需要创建文件夹结构。

        然后app/code/local/company_name/module_name/etc/config.xml

        <?xml version="1.0"?>
        <config>
            <modules>
                <JR_CreateAdminController>
                    <version>1.0.0</version>
                </JR_CreateAdminController>
            </modules>
            <global>
                <helpers>
                    <jr_createadmincontroller>
                        <!-- Helper definition needed by Magento -->
                        <class>Mage_Core_Helper</class>
                    </jr_createadmincontroller>
                </helpers>
            </global>
            <admin>
                <routers>
                    <adminhtml>
                        <args>
                            <modules>
                                <foo_bar before="Mage_Adminhtml">JR_CreateAdminController_Adminhtml</foo_bar>
                            </modules>
                        </args>
                    </adminhtml>
                </routers>
            </admin>
        </config>
        

        然后您使用这种方式创建管理面板菜单app/code/community/company_name/module_name/etc/adminhtml.xml

        <?xml version="1.0" encoding="UTF-8"?>
        <config>
            <menu>
                <mycustomtab module="jr_createadmincontroller" translate="title">
                    <title>My Custom Tab</title>
                    <sort_order>100</sort_order>
                    <children>
                        <index module="jr_createadmincontroller" translate="title">
                            <title>Index Action</title>
                            <sort_order>1</sort_order>
                            <action>adminhtml/custom</action>
                        </index>
                        <list module="jr_createadmincontroller" translate="title">
                            <title>List Action</title>
                            <sort_order>2</sort_order>
                            <action>adminhtml/custom/list</action>
                        </list>
                    </children>
                </mycustomtab>
            </menu>
            <acl>
                <resources>
                    <admin>
                        <children>
                            <custom translate="title" module="jr_createadmincontroller">
                                <title>My Controller</title>
                                <sort_order>-100</sort_order>
                                <children>
                                    <index translate="title">
                                        <title>Index Action</title>
                                        <sort_order>1</sort_order>
                                    </index>
                                    <list translate="title">
                                        <title>List Action</title>
                                        <sort_order>2</sort_order>
                                    </list>
                                </children>
                            </custom>
                        </children>
                    </admin>
                </resources>
            </acl>
        </config>
        

        您可以为您的模块创建自己的控制器 app/code/community/company_name/module_name/controllers/Adminhtml/CustomController.php

        <?php
        
        class JR_CreateAdminController_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
        {
            public function indexAction()
            {
                $this->loadLayout()
                    ->_setActiveMenu('mycustomtab')
                    ->_title($this->__('Index Action'));
        
                // my stuff
        
                $this->renderLayout();
            }
        
            public function listAction()
            {
                $this->loadLayout()
                    ->_setActiveMenu('mycustomtab')
                    ->_title($this->__('List Action'));
        
                // my stuff
        
                $this->renderLayout();
            }
        }
        

        并且您想创建配置选项卡: 创建 system.xml 并使用此代码

        <?xml version="1.0" encoding="UTF-8"?>
        <config>
            <tabs>
                <inchoo translate="label" module="mymodule">
                    <label>Inchoo Extensions</label>
                    <sort_order>100</sort_order>
                </inchoo>
            </tabs>
            <sections>
                <inchoo translate="label" module="mymodule">
                    <label>Extension Options</label>
                    <tab>inchoo</tab>
                    <sort_order>1000</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <groups>
                        <inchoo_group translate="label" module="mymodule">
                            <label>My Extension Options</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>1000</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <fields>
                                <inchoo_input translate="label">
                                    <label>My Input Field: </label>
                                    <comment>My Comment</comment>
                                    <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>
                                </inchoo_input>
                                <inchoo_select translate="label">
                                    <label>My Dropdown: </label>
                                    <comment>Source model provider Magento's default Yes/No values</comment>
                                    <frontend_type>select</frontend_type>
                                    <sort_order>90</sort_order>
                                    <show_in_default>1</show_in_default>
                                    <show_in_website>1</show_in_website>
                                    <show_in_store>1</show_in_store>
                                    <source_model>adminhtml/system_config_source_yesno</source_model>
                                </inchoo_select>
                            </fields>
                        </inchoo_group>
                    </groups>
                </inchoo>
            </sections>
        </config>
        

        我相信这对你有用。

        【讨论】:

          【解决方案6】:

          您没有遇到此问题,但为了后代,我注意到如果您的 /app/etc/modules/New_Storeinfo.xml 文件中有任何 cmets,该模块将不会显示在系统 > 配置 > 高级 > 高级 :: 禁用模块中输出

          【讨论】:

            猜你喜欢
            • 2013-10-06
            • 1970-01-01
            • 1970-01-01
            • 2020-04-20
            • 2018-05-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多