Magento 1.9 – Fix Controller Action Name Displaying in Frontend

actioncontrollersevent-observermagento-1.9module

I am trying to find controller action of module for below Observer code, so that i can see those action names in log file : called_action_names.log , its displaying those names in log files.

issue : along with this its displaying those names in site & now its not saving the uploaded image in site once we click on "save design" button.

you can see text catalog_product_view in top of the page

public function onControllerActionPredispatch($observer)
    {
      Mage::log($observer->getEvent()->getControllerAction()->getFullActionName(), Zend_Log::DEBUG, 'called_action_names.log');
        if (
            $observer->getEvent()->getControllerAction()->getFullActionName() == 'example_amasty_createProduct' &&
            !Mage::getSingleton('customer/session')->isLoggedIn()
        ) {
            Mage::getSingleton('customer/session')->setAmastyExampleCustomProductInfo(
                $observer->getEvent()->getControllerAction()
                    ->getRequest()->getPost('Amasty')
            );
        }
        else if (
            Mage::getSingleton('customer/session')->isLoggedIn() &&
            Mage::getSingleton('customer/session')->getAmastyExampleCustomProductInfo()
        ) {

        }

     echo $observer->getEvent()->getControllerAction()->getFullActionName();
    }

   }

config.xml

<controller_action_predispatch>
            <observers>
                <Amasty_Example>
                    <class>example/observer</class>
                    <method>onControllerActionPredispatch</method>
                </Amasty_Example>
            </observers>
</controller_action_predispatch>

when i replace line : <class>example/observer</class> by <class>my_module/observer</class> , it dont show any issue. but real module name is "example".

Best Answer

You need to remove echo from your observer code.

public function onControllerActionPredispatch($observer)
{
  Mage::log($observer->getEvent()->getControllerAction()->getFullActionName(), Zend_Log::DEBUG, 'called_action_names.log');
    if (
        $observer->getEvent()->getControllerAction()->getFullActionName() == 'example_amasty_createProduct' &&
        !Mage::getSingleton('customer/session')->isLoggedIn()
    ) {
        Mage::getSingleton('customer/session')->setAmastyExampleCustomProductInfo(
            $observer->getEvent()->getControllerAction()
                ->getRequest()->getPost('Amasty')
        );
    }
    else if (
        Mage::getSingleton('customer/session')->isLoggedIn() &&
        Mage::getSingleton('customer/session')->getAmastyExampleCustomProductInfo()
    ) {

    }
}