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.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
scroll top