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.

asked Sep 18, 2020 at 11:16
3
  • have you tried - magentowebsite.co/admin/my_orders/index ? Commented Sep 18, 2020 at 11:33
  • Thenk you @Hamendra Sunthwal for responding, Yes I tried as http://magentowebsite.co/admin/my_orders/index/ still its Error: 404 Commented Sep 18, 2020 at 11:37
  • I have added an answer. Commented Sep 18, 2020 at 11:38

1 Answer 1

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

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

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.