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.

poojan sharma
1,5561 gold badge11 silver badges16 bronze badges
asked Jun 19, 2019 at 17:03
1
  • Try $this->getRequest()->getFullActionName() or use \Magento\Framework\App\RequestInterface instead of \Magento\Framework\App\Request\Http 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

answered Jun 19, 2019 at 17:42
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()
answered Jun 19, 2019 at 17:47
1
  • This I tried it will not work...I m asking about ajax controller. Commented Jun 19, 2019 at 18:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.