I have added a sample custom module in Magento 2. I have two controller function for admin panel page,
http://127.0.0.1/magento2/admin_magento2/sample/index/index/
http://127.0.0.1/magento2/admin_magento2/sample/sampletwo/index/
First url only display page. The second one displays 404 or redirecting to dashboard.
Please help me someone to solve this.
Note
I have added admin panel menu for first url only.
app\code\Test\Sample\Controller\Adminhtml\Index\Index.php
namespace Test\Sample\Controller\Adminhtml\Index;
class Index extends \Magento\Backend\App\Action
{
public function execute()
{
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
}
app\code\Test\Sample\Controller\Adminhtml\Sampletwo\Index.php
namespace Test\Sample\Controller\Adminhtml\Sampletwo;
class Index extends \Magento\Backend\App\Action
{
public function execute()
{
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
}
app\code\Test\Sample\etc\adminhtml\menu.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Backend/etc/menu.xsd">
<menu>
<add id="Test_Sample::parent" title="Sample" module="Test_Sample" sortOrder="100" resource="Test_Sample::parent"/>
<add id="Test_Sample::index" title="Sample Index" module="Test_Sample" sortOrder="10" action="sample/index" resource="Test_Sample::index" parent="Test_Sample::parent"/>
</menu>
</config>
app\code\Test\Sample\etc\adminhtml\routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="admin">
<route id="sample" frontName="sample">
<module name="Test_Sample" before="Magento_Adminhtml" />
</route>
</router>
</config>