0

我按照本教程 http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-2-the-magento-config

当我运行 URL 时,它不显示配置,不工作。下面是我的代码。

配置文件

<config>
<modules>
    <Magentotutorial_Configviewer>
        <version>0.1.0</version>
    </Magentotutorial_Configviewer>
</modules>
<global>
    <events>
        <controller_front_init_routers>
            <observers>
                <Magentotutorial_configviewer_model_observer>
                    <type>singleton</type>
                    <class>Magentotutorial_Configviewer_Model_Observer</class>
                    <method>checkForConfigRequest</method>
                </Magentotutorial_configviewer_model_observer>
            </observers>
        </controller_front_init_routers>
    </events>
</global>

Magentotutorial_Configviewer.xml

<config>
<modules>
    <Magentotutorial_Configviewer>
        <active>true</active>
        <codePool>local</codePool>
    </Magentotutorial_Configviewer>
</modules>

模型中的 Observer.php

 <?php
class Magentotutorial_Configviewer_Model_Observer {
    const FLAG_SHOW_CONFIG = 'showConfig';
    const FLAG_SHOW_CONFIG_FORMAT = 'showConfigFormat';

    private $request;

    public function checkForConfigRequest($observer) {
        $this->request = $observer->getEvent()->getData('front')->getRequest();
        if ($this->request->FLAG_SHOW_CONFIG === 'true') {
            $this->setHeader();
            $this->outputConfig();
        }
    }

    private function setHeader() {
        $format = isset ( $this->request->FLAG_SHOW_CONFIG_FORMAT ) ? $this->request->FLAG_SHOW_CONFIG_FORMAT : 'xml';
        switch ($format) {
            case 'text' :
                header("Content-Type: text/plain");
                break;
            default :
                header("Content-Type: text/xml");
        }
    }

    private function outputConfig() {
        die( Mage::app()->getConfig()->getNode()->asXML() );
    }
}
?>
4

2 回答 2

0

您没有关闭 config 标签,这将导致 Magento 失败。同样,在您的模块声明中,配置标签​​也没有被关闭。

以下带有封闭标签的内容应该可以工作:

<config>
  <modules>
    <Magentotutorial_Configviewer>
      <version>0.1.0</version>
    </Magentotutorial_Configviewer>
 </modules>
<global>
  <events>
    <controller_front_init_routers>
        <observers>
            <Magentotutorial_configviewer_model_observer>
                <type>singleton</type>
                <class>Magentotutorial_Configviewer_Model_Observer</class>
                <method>checkForConfigRequest</method>
            </Magentotutorial_configviewer_model_observer>
        </observers>
    </controller_front_init_routers>
   </events>
 </global>
</config>

和模块声明:

<config>
  <modules>
    <Magentotutorial_Configviewer>
      <active>true</active>
      <codePool>local</codePool>
    </Magentotutorial_Configviewer>
  </modules>
</config>

您可以通过 using 检查模块是否正在运行(将其放在您声明的方法中):

Mage::log('message');

在观察者中使用 echo 或 var_dump 除非为渲染器使用特定事件往往不会显示任何内容。日志记录是后端项目的前进方向。

它将出现在您的 system.log 中的 var/logs 中。

于 2013-07-04T10:03:09.103 回答
0

去除开口前的空间

于 2014-05-12T12:07:09.683 回答