0

I followed every step from this website : http://alanstorm.com/magento_config and I'm stuck with the observer.

I think smth is wrong with my Observer.php. I get this error :

a:5:{i:0;s:157:"Cannot send headers; headers already sent in /mnt/futurehome/netlogiq/public_html/attin/magento/app/code/local/Attila/Configviewer/Model/Observer.php, line 1";i:1;s:1142:"#0 /mnt/futurehome/netlogiq/public_html/attin/magento/lib/Zend/Controller/Response/Abstract.php(115): Zend_Controller_Response_Abstract->canSendHeaders(true).....

I post this image : enter image description here

Also I comment the code from observer I did not get this error. Can someone help me with this ?

=> config.xml :

<config>
    <modules>...</modules>
    <global>
        <events>
            <controller_front_init_routers>
                <observers>
                    <attila_configviewer_model_observer>
                        <type>singleton</type>                          
                        <class>Attila_Configviewer_Model_Observer</class>
                        <method>checkForConfigRequest</method>
                    </attila_configviewer_model_observer>
                </observers>
            </controller_front_init_routers>
        </events>
    </global>
</config>

=> Observer.php :

 <?php
    class Attila_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());      
        }
    }
?>
4
  • please share some of your code which you tried.if their is problem in code we can help you. Commented May 9, 2014 at 6:53
  • please check the post again :) Commented May 9, 2014 at 6:56
  • make sure that in the file Attila/Configviewer/Model/Observer.php you don't have any space or other character before the php opening tag (<?php) or after the closing tag ?>. Actually you can remove the closing tag completely if you have one.
    – Marius
    Commented May 9, 2014 at 6:56
  • @Marius thx man , that was the problem :D can I add you on skype ? Commented May 9, 2014 at 6:59

1 Answer 1

0

So this question will have an answer.

Based on the comments the problem was cause by a character (probably space) at the beginning of the observer file, before the php opening tag (<?php) and it was considered output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.