2

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.

  • Try $this->getRequest()->getFullActionName() or use \Magento\Framework\App\RequestInterface instead of \Magento\Framework\App\Request\Http – Amit Bera Jun 19 at 17:45
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

0

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()
  • This I tried it will not work...I m asking about ajax controller. – Deepak Rai Jun 19 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.