我遵循了本教程 http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-2-the-magento-config
当我运行URL时,它不显示配置,不起作用。下面是我的代码。
config.xml中
<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() );
}
}
?>
答案 0 :(得分:0)
你没有关闭配置标签,这会导致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>
您可以检查模块是否正在运行(将其放在声明的方法中):
Mage::log('message');
在观察者中使用echo或var_dump,除非为渲染器使用特定事件,否则不会显示任何内容。日志记录是后端项目的前进方向。
它将出现在var / logs中的system.log中。
答案 1 :(得分:0)
移除开口前方的空间