我从Magento for Developers指南开始学习magento。所以我用他们的名字创建模块。但是当我尝试http://works.dev/magento/?showConfig=true时,它显示以下错误。
XML Parsing Error: XML or text declaration not at start of entity
Location: http://works.dev/magento/?showConfig=true
Line Number 1, Column 2: <?xml version="1.0"?>
-^
(works.dev是我的localhost域.magento路径工作正常。)
这是我的配置文件。
应用程序/代码/本地/ Magentotutorial / Configviewer的/ etc / config.xml中
<?xml version="1.0"?>
<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>
应用程序的/ etc /模块/ Magentotutorial_Configviewer.xml
<?xml version="1.0"?>
<config>
<modules>
<Magentotutorial_Configviewer>
<active>true</active>
<codePool>local</codePool>
</Magentotutorial_Configviewer>
</modules>
</config>
应用程序/代码/本地/ Magentotutorial / Configviewer /型号/ 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->{self::FLAG_SHOW_CONFIG} === 'true'){
$this->setHeader();
$this->outputConfig();
}
}
private function setHeader() {
$format = isset($this->request->{self::FLAG_SHOW_CONFIG_FORMAT}) ?
$this->request->{self::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 :(得分:1)
据@JürgenThelen说这是空间问题。在删除空间之前它已经工作了
答案 1 :(得分:0)
Ausuraya,请你改变config.xml
<global>
<models>
<configviewer>
<class>Magentotutorial_Configviewer_Model</class>
</configviewer>
</models>
<events>
<controller_front_init_routers>
<observers>
<Magentotutorial_configviewer_model_observer>
<type>singleton</type>
<class>configviewer/observer</class>
<method>checkForConfigRequest</method>
</Magentotutorial_configviewer_model_observer>
</observers>
</controller_front_init_routers>
</events>
</global>