3

I need Full Action Name in Ajax Controller Magento 2.

protected $request;
public function __construct(
    ...
    \Magento\Framework\App\Request\Http $request
) {

    $this->request = $request;
}

$action = $this->request->getFullActionName();

This always giving me my ajax controller full action name.

I need, suppose if I m on the product page this should give me "catalog_product_view".

If I m on search this should display "catalogsearch_result_index".

Please help.

1
  • Try $this->getRequest()->getFullActionName() or use \Magento\Framework\App\RequestInterface instead of \Magento\Framework\App\Request\Http
    – Amit Bera
    Commented Jun 19, 2019 at 17:45

2 Answers 2

2

Use following code to check controller, module and action

echo $controllerName = $this->request->getControllerName();
echo $actionName = $this->request->getActionName();
echo $routeName = $this->request->getRouteName();
echo $moduleName = $this->request->getModuleName(); 

By concatenation, you can get your required result

1

You can use this code to get your result

protected $request;
public function __construct(
    ...
    \Magento\Framework\App\Request\Http $request
) {

    $this->request = $request;
}

$action = $this->request->getModuleName()."_".$this->request->getControllerName()."_".$this->request->getActionName()
1
  • This I tried it will not work...I m asking about ajax controller.
    – Deepak Rai
    Commented Jun 19, 2019 at 18:21

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.