0

Here am added a admin controller, here is my code

etc/adminhtml/routes.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route frontName="my_orders" id="my_orders">
            <module name="My_Orders" before='Magento_Backend'/>
        </route>
    </router>
</config>

Here is the controller file

My/Orders/Controller/Adminhtml/Index/Index.php

<?php

namespace My\Orders\Controller\Adminhtml\Index;

    class Index extends \Magento\Backend\App\Action
    {
         public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\Registry $coreRegistry,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory
        ) {
            $this->resultPageFactory = $resultPageFactory;
            parent::__construct($context, $coreRegistry); 
        }
        public function execute()
        {
           $result = $this->resultPageFactory->create(ResultFactory::TYPE_RAW);
           echo "save contoller";
           
        }
          protected function _isAllowed()
        {
            return true;
        }
    }
    ?>

When I try to access the Controller its giving Error:404

Url path is

http://magentowebsite.co/admin/my_orders/index/index

Where am doing wrong. Can I get help? Thank you in advance.

3
0

File: app/code/Retailinsights/Orders/etc/adminhtml/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="retailinsights_orders" frontName="retailinsights_orders">
            <module name="Retailinsights_Orders"/>
        </route>
    </router>
</config>

Create controller file called index.php

app/code/Retailinsights/Orders/Controller/Adminhtml/Post/Index.php With the following content:

<?php

namespace Retailinsights\Orders\Controller\Adminhtml\Post;

class Index extends \Magento\Backend\App\Action
{
    protected $resultPageFactory = false;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    )
    {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        echo'controller'; exit;
    }
}

Browse - localhost.com/retailinsights_orders/post/index

2
  • Let me know if it works for you. Sep 18 '20 at 11:54
  • Thank you @Hamendra Sunthwal, this is Working for me Sep 18 '20 at 11:56

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.