I am trying to display something when click on a link from admin menu. So i created a simple module and when i click from the admin menu it redirect to mydomain/secure-manage/helloworld/index/index/key/… with status 200 but the page is blank.
In devtool i can see the css and js are loaded but nothing inside the body tag.
1.folder structure
Inchoo
Helloworld
-Block
-Adminhtml
Helloworld.php
-Controller
-Adminhtml
-Index
Index.php
-etc
-module.xml
-adminhtml
-menu.xml
-routes.xml
-view
adminhtml
layout
-helloworld_index_index.xml
templates
-helloworld.phtml
registration.php
2.Block/Adminhtml/Helloworld.php
<?php
namespace Inchoo\Helloworld\Block;
class Helloworld extends \Magento\Framework\View\Element\Template
{
public function getHelloWorldTxt()
{
return 'Hello world!';
}
}
3.Controller/Adminhtml/Index/Index.php
<?php
namespace Inchoo\Helloworld\Controller\Adminhtml\Index;
use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_resultPageFactory;
public function __construct(Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory)
{
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$resultPage = $this->_resultPageFactory->create();
// print_r($resultPage);exit;
return $resultPage;
}
}
4.etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/
module.xsd">
<module name="Inchoo_Helloworld" setup_version="1.0.0">
</module>
</config>
5.etc/adminhtml/menu.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc
/menu.xsd">
<menu>
<add id="Inchoo_Helloworld::first_pincollect_pincheck"
title="Greetings"
module="Inchoo_Helloworld"
sortOrder="50"
dependsOnModule="Inchoo_Helloworld"
resource="Magento_Backend::content" />
<add id="Inchoo_Helloworld::second_pincollect_pincheck"
title="Manage Pincodes"
module="Inchoo_Helloworld"
sortOrder="0"
action="helloworld/index"
parent="Inchoo_Helloworld::first_pincollect_pincheck"
resource="Magento_Backend::content" />
</menu>
</config>
6.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="helloworld" frontName="helloworld">
<module name="Inchoo_Helloworld" />
</route>
</router>
</config>
7.view/adminhtml/layout/helloworld_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../lib/
internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"
layout="1column">
<body>
<referenceContainer name="content">
<block class="Inchoo\Helloworld\Block\Adminhtml\Helloworld"
name="helloworld" template="helloworld.phtml" />
</referenceContainer>
</body>
</page>
8.view/adminhtml/templates/helloworld.phtml
<p>Hello World!</p>
how can i debug this, please help me guys.
Thanks in advance.
Best Answer
I am giving you the exact code and path please copy and paste the below file.
app/code/Inchoo/Helloworld/registration.php
app/code/Inchoo/Helloworld/Block/Adminhtml/Index/Index.php
app/code/Inchoo/Helloworld/Controller/Adminhtml/Index/Index.php
app/code/Inchoo/Helloworld/etc/module.xml
app/code/Inchoo/Helloworld/etc/adminhtml/routes.xml
app/code/Inchoo/Helloworld/etc/adminhtml/menu.xml
app/code/Inchoo/Helloworld/view/adminhtml/layout/helloworld_index_index.xml
app/code/Inchoo/Helloworld/view/adminhtml/templates/helloworld_index_index.phtml
N:B After put all the files to the specific path don't forget to run this command from CLI -