0

I'm new in Magento2 and I want to know the detail of controller_action_postdispatch events like controller Name, action name,module name and all the details related to that event. I have created an events.xml file where I called the event name then try to get the details from the observer. My question is how to get the details on that event? I have found $this->_request->getControllerModule(); but I couldn't use \Magento\Framework\App\Request\Http $request in observer.

Is there any

Here is my events.xml code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_postdispatch">
        <observer name="category" instance="Comlitix\ComlitixInfo\Observer\Category"/>
    </event>
</config>

Here is observer file

<?php

namespace Comlitix\ComlitixInfo\Observer;

use Magento\Framework\Event\Manager;

class Category implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        echo'Hello world';
        die;

    }
}

2 Answers 2

0

the below are all variables that do exist in your event:

$event = $observer->getEvent();
$controller = $observer->getControllerAction();
$request = $observer->getRequest();
0

your event.xml is containing only controller_action_postdispatch which is not correct:

Below are controller action events:

Controllers:

  • controller_action_predispatch_ [ROUTE_NAME]
  • controller_action_predispatch_ [FULL_ACTION_NAME]
  • controller_action_postdispatch_ [ROUTE_NAME]
  • controller_action_postdispatch_ [FULL_ACTION_NAME]
  • controller_action_layout_render_before_ [FULL_ACTION_NAME]

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.