I have referred below Article to display button in my Configuration page.


In file


there is a function where we can define our Ajax URL

public function getAjaxUrl()
        return $this->getUrl(‘your action Url’);

So for this, I want to create controller in Adminhtml which i can access using action url. but all the examples i found also creates menu in sidebar in addition to controller action.

For example this one: https://www.maximehuran.fr/en/admin-controller-creation-with-magento-2/

Is there any way to access controller action without creating menu?

Edit: After some modification to code, I can get into the controller using below URL:


but it redirects back me to Dashboard page.

As mentioned in this article:

Magento 2 Custom Admin Action Redirected to Dashboard

It's Secret Form Key issue.

We can get Secret form key only if we add controller to menu which i don't want to do!

Disabling Secret Form key is not what i prefer!

  • menu file is used to display menu in admin backend Jun 19, 2019 at 11:47
  • yes i know and i don't want to display in menu. so i have not created menu.xml file
    – Khushbu
    Jun 19, 2019 at 11:50
  • you can create controller without menu file but you can call controller using url Jun 19, 2019 at 11:54
  • yes but i am not able to call controller using url
    – Khushbu
    Jun 19, 2019 at 11:55
  • like this www.abc.com/admin/yout_route_id/controller_name Jun 19, 2019 at 12:04

2 Answers 2


Answer which worked for me is from this article:

Magento 2 Custom Admin Action Redirected to Dashboard

We can use protected $_publicActions = ['ENTER_NAME_OF_ACTION']; to turn off form key validation for specific controller like below:

class Index extends \Magento\Backend\App\Action
    protected $_publicActions = ['index'];

    public function execute()
        echo "My Hello World! Controller";


It's better to disable form key for only my controller instead of everywhere in admin panel.

Please share if anyone has any better solution.


Your namespace should be uppercase, not lowercase, if you want to go step by step How do I create a controller in magento 2


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.