【问题标题】:Enable template path hint in admin pages - Magento在管理页面中启用模板路径提示 - Magento
【发布时间】:2010-12-07 04:44:45
【问题描述】:

我想在管理面板中启用模板路径提示。我知道如何为前端做到这一点,但对于后端?我实际上想编辑管理面板。

提前谢谢..

【问题讨论】:

    标签: php api magento e-commerce


    【解决方案1】:

    您可以通过直接更改数据库来实现。如果您有类似 phpMyAdmin 的东西,这是获得访问权限的好方法。输入此 SQL。

    INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`)
           VALUES ('websites', '0', 'dev/debug/template_hints', '1');
    

    当您完成路径提示后,只需从core_config_data 中删除匹配记录,或者将value 字段更新为0,而不是删除整个记录,它可能是您刚刚添加的最后一个记录它。

    【讨论】:

    • 如果此解决方案对您不起作用,可能是因为您在developer > Developer Client Restrictions 下配置的 IP 与您当前的 IP 不匹配
    • 不要忘记您需要刷新 Magento 的缓存才能看到新设置生效。
    • 我建立了一个模块来启用管理员提示,希望这可以帮助其他人github.com/ledian-hymetllari/adminhints
    • 最好避免直接在DB中修改,配置文件是更好的解决方案。
    【解决方案2】:

    您可以通过在 Magento 配置中设置它们来在每个商店(包括管理商店)中启用模板和块路径提示。为此,只需编辑模块的配置文件config.xml(它被注入到 Magento 的全局配置中)。

    要在管理区域中启用模板和阻止路径提示,请将其添加到您的 config.xml 文件中

    <config>
    
        ...
    
        <stores>
            <admin>
                <dev>
                    <debug>
                        <template_hints>1</template_hints>
                        <template_hints_blocks>1</template_hints_blocks>
                    </debug>
                </dev>
            </admin>
        </stores>
    
    </config>
    

    要禁用路径提示,只需更改为 0,或删除节点。

    【讨论】:

      【解决方案3】:

      打开/app/etc/local.xml并添加以下代码

      <config>
      
          ...
      
          <websites>
              <admin>
                  <dev>
                      <debug>
                          <template_hints>1</template_hints>
                          <template_hints_blocks>1</template_hints_blocks>
                      </debug>
                  </dev>
              </admin>
          </websites>
      </config>
      

      【讨论】:

        【解决方案4】:

        该功能并非设计用于管理员。它的系统配置被明确设置为仅允许您在网站或商店级别进行设置,而不是全局级别。

        假设这只是为了在开发环境中工作,我会采取的方法是覆盖类

        Mage_Core_Block_Template
        

        并覆盖(使用类别名覆盖,或本地/法师替换)getShowTemplateHints 方法提示。

        public function getShowTemplateHints()
        {
             //return false
             return true; 
        }
        
        //     old method, here for demo purposes only.  Don't hack the core
        //     public function getShowTemplateHints()
        //     {
        //         if (is_null(self::$_showTemplateHints)) {
        //             self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
        //                 && Mage::helper('core')->isDevAllowed();
        //             self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
        //                 && Mage::helper('core')->isDevAllowed();
        //         }
        //         return self::$_showTemplateHints;
        //     }
        

        然后,您可以手动更改 getShowTemplateHints 以返回 true 或 false,如果您想要打开或关闭该功能,或者添加您想要的任何其他逻辑。

        我不建议您将此更改推送到生产服务器。

        【讨论】:

          【解决方案5】:

          您可以使用以下扩展,以便以 joomla 方式轻松安全地启用前端和后端的模板路径提示:
          http://www.magepsycho.com/easy-template-path-hints.html

          【讨论】:

            【解决方案6】:

            一个非常方便的解决方案:修改\app\code\core\Mage\Adminhtml\Block\Template.php文件中定义的getShowTemplateHints()函数如下:

            要运行以下函数:在您的浏览器中输入http://www.mymagentosite.com/?th=1&token=PHP

            您可以看到模板提示和添加的块名称。

            public function getShowTemplateHints()
            {
                if (is_null(self::$_showTemplateHints))
                {
                    self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
                        && Mage::helper('core')->isDevAllowed();
                    self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
                        && Mage::helper('core')->isDevAllowed();
                }
            
                // overwrite the template hint [SPECIALLY FOR SHOWING TEMPLATE PATH HINTS IN ADMIN]
                $th     = Mage::app()->getRequest()->getParam('th', false);
                $token  = Mage::app()->getRequest()->getParam('token', false);
                if($th == 1 && $token == 'PHP'){
                    self::$_showTemplateHints = true; // for template path
                    self::$_showTemplateHintsBlocks = true; // block names
                }
            
                return self::$_showTemplateHints;
            }
            

            【讨论】:

            • \app\code\core\Mage\Adminhtml\Block\Template.php 文件现在在 magento 版本 1.9.3.0 中没有任何 getShowTemplateHints() 函数
            【解决方案7】:

            我知道现在很晚,但您可以通过以下方式轻松完成: 只需更改配置文件中的设置www/app/code/core/Mage/Core/etc/system.xml

            sections&gt;dev&gt;debug&gt;fields&gt;template_hints&gt;show_in_default 设置为1 和 也将sections&gt;dev&gt;debug&gt;fields&gt;template_hints_blocks&gt;show_in_default 设置为1

            【讨论】:

            • 这不会影响管理页面。
            • 确实如此。 template_hints show_in_default 将允许您在 Default 上查看选择器,而不是在网站上。我实际上正在使用它并且它正在工作。
            【解决方案8】:

            转到您的数据库并运行以下查询:

            INSERT INTO core_config_data (scope, scope_id, path, value)
            VALUES ('default', 0, 'dev/debug/template_hints', 1),
            ('default', 0, 'dev/debug/template_hints_blocks', 1);
            

            要再次禁用它们,请运行以下查询:

            UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints'
            

            要再次启用,请运行此查询:

            UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints'
            

            【讨论】:

              【解决方案9】:

              我认为你不应该把它弄得太难,让我们通过简单的步骤让它变得简单。你可以看看这里关于How to turn on template path hints in Magento的说明

              【讨论】:

              • 问题是后端调试而不是前端。 @Phuc
              • 管理员的问题,你在谈论前端
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2016-05-08
              • 2021-11-20
              • 1970-01-01
              • 2017-12-17
              相关资源
              最近更新 更多