Listen to an event with an observer in Magento
Learn how to listen to Magento events with observers and log blog post detail view request data.
Lesson Content
Letβs say we wanted to listen for this macademy_blog_post_detail_view event and carry out an action on it, such as outputting the page response to a log file. We can do this with an observer.
Observers are the other half of an event, and allow you to carry out an action that requires no response by the code that has dispatched an event. Observers work from the relationship between two files: an XML file and a related PHP class that is the observer. The XML defines which event youβd like to listen to, and it references the PHP class that is observing this event:
![](https://codex-assets...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.