Reputation: 95
I have created my custom module in magento at app/code/local/mycustom/GeoLocation, in that i want to create a observer so i had followed lot of tutorials and at last i had created below code to call it on every page load of magento but still it is not calling my observer.php of custom module.I am new to magento so please help me.
config.xml
<config>
<global>
<events>
<cms_page_render>
<observers>
<mycustom_GeoLocation_Model_observer>
<type>singleton</type>
<class>mycustom_GeoLocation_Model_Observer</class>
<method>getGeoLocation</method>
</mycustom_GeoLocation_Model_observer>
</observers>
</cms_page_render>
</events>
</global>
</config>
mycustomGeolocation_Event.xml for enabling module
<config>
<modules>
<mycustom_GeoLocation>
<active>true</active>
<codepool>local</codepool>
</mycustom_GeoLocation>
</modules>
</config>
At last my observer.php which is present in model of my custom module
class mycustom_GeoLocation_Model_Observer {
public function __construct()
{
}
public function getGeoLocation(Varien_Event_Observer $observer) { // current layout
$event = $observer->getEvent();
$cms_page = $event->getPage();
echo "called";
exit;
return $this;
}
}
Upvotes: 4
Views: 695
Reputation: 7611
There are lots of issue in modules.
As observer die() may be not works
.Use Magento log print to check the observer work or not
Module NameSpace Folder name should be start with upper letter mycustom to Mycustom
. Also You need change class name respesctive code.
config.xml code :
<?xml version="1.0"?>
<config>
<modules>
<Mycustom_GeoLocation>
<version>0.1.0</version>
</Mycustom_GeoLocation>
</modules>
<global>
<models>
<geolocation>
<class>Mycustom_GeoLocation_Model</class>
</geolocation>
</models>
<events>
<cms_page_render>
<observers>
<cms_page_render_handler>
<type>model</type>
<class>geolocation/observer</class> <!-- observers class alias -->
<method>getGeoLocation</method>
</cms_page_render_handler>
</observers>
</cms_page_render>
</events>
</global>
</config>
You can get full module at github
Upvotes: 1