1

I made a custom admin menu item in Magento 2 and the menu item is pointing to the Magento2 Pages URL. I want the menu item to point to a custom module URL

Custom module URL is

http://127.0.0.1/magento/demo/helloworld

Here is the link to all the files and folders of my Custom Module in Magento2

https://github.com/sneurgaonkar/HelloWorld.git

2

You need to add menus at Acl resource

So you need to create acl.xml at HelloWorld/etc/ and at menu item at there.

Acl code may:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Magento_Backend::content">
                    <resource id="Magento_Backend::content_elements">
                        <resource id="Webmull_Helloworld::demo_menu_item" title="Demo Menu Item" sortOrder="20" />
                        <resource id="Webmull_Helloworld::demo_menu_item1" title="Demo Menu Item1" sortOrder="30"/>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

After that you need to flush cache.

  • Okay. I got it. But one more question is.. where do i have to provide the link to my module? – Sunil Neurgaonkar Jun 7 '16 at 6:33
2

You can try:

  1. add the link to your controller in the menu (file /etc/adminhtml/menu.xml)

  2. create your custom admin controller (class in VENDOR/MODULE/Controller/Adminhtml/...) something like:

    <?php
    
    namespace VENDOR\MODULE\Controller\Adminhtml\Test;
    
    use Magento\Backend\App\Action;
    
    class Redirect extends Action
    {
         public function execute()
         {
             $resultRedirect = $this->resultRedirectFactory->create();
             $resultRedirect->setUrl($this->getImportUrl());
             return $resultRedirect; //<---- return is important
         }
    
         private function getImportUrl()
         {
            return 'https://www.google.com/';
         }
    }
    

Note: do not forget about return in controller

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.