cancel
Showing results for 
Search instead for 
Did you mean: 

Data in custom admin module not showing up

Data in custom admin module not showing up

Hi, 

I have followed exact steps given in the below magento guide link but no data is showing in the custom php page.

https://devdocs.magento.com/guides/v2.0/ext-best-practices/extension-coding/example-module-adminpage...

 

Please help 

Magento no data.png

 

3 REPLIES

Re: Data in custom admin module not showing up

Hi @neelav_barai,


Can you check your module structure?

 

    MyCompany
    `-- ExampleAdminNewPage
        |
        |-- Controller
        |   |-- Adminhtml
        |       |-- HelloWorld
        |           `-- Index.php
        |-- etc
        |   |-- adminhtml
        |   |   |-- menu.xml
        |   |   `-- routes.xml
        |   `-- module.xml
        |-- view
        |   |-- adminhtml
        |       |-- layout
        |       |    `-- exampleadminnewpage_helloworld_index.xml
        |       `-- templates
        |           `-- helloworld.phtml
        |-- composer.json
        `-- registration.php

Are the layout and template files in the right place?

Did you refreshed cache?

In which mode is your application?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Data in custom admin module not showing up

Hi @Damian Culotta,

 

Yes the directory structure is correct, I have double checked it.

I have complied megento after completion, i have done any deletion of cache, can it do it like this : 

php -f bin/magento cache:flush

I am running in developer mode.

Below is my complete code:

 

C:\xampp\htdocs\app\code\BBC\ProdAdmin\composer.jason

{"name": "bbc/ProdAdmin",
  "description": "A module that creates a page in the Magento admin area",
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "require": {
    "php": "~5.6.0|7.0.2|7.0.4|~7.0.6"
  },
  "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "BBC\\ProdAdmin\\": ""
    }
  }}

C:\xampp\htdocs\app\code\BBC\ProdAdmin\registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'BBC_ProdAdmin',
    __DIR__
);

C:\xampp\htdocs\app\code\BBC\ProdAdmin\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="BBC_ProdAdmin" setup_version="1.0.0">
  </module>
</config>

C:\xampp\htdocs\app\code\BBC\ProdAdmin\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="BBC_ProdAdmin::greetings" title="Prod Admin Panel" translate="title" module="BBC_ProdAdmin" parent="Magento_Backend::content" sortOrder="50" dependsOnModule="BBC_ProdAdmin" resource="BBC_ProdAdmin::greetings"/>
      <add id="BBC_ProdAdmin::greetings_helloworld" title="Admin Access" translate="title" module="BBC_ProdAdmin" parent="BBC_ProdAdmin::greetings" sortOrder="10" dependsOnModule="BBC_ProdAdmin" action="prodadmin/ProdAdminControl" resource="BBC_ProdAdmin::greetings"/>
    </menu>
</config>

C:\xampp\htdocs\app\code\BBC\ProdAdmin\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="prodadmin" frontName="prodadmin">
          <module name="BBC_ProdAdmin"/>
      </route>
  </router>

C:\xampp\htdocs\app\code\BBC\ProdAdmin\Controller\Adminhtml\ProdAdminControl\Index.php

<?php namespace BBC\ProdAdmin\Controller\Adminhtml\ProdAdminControl;

  class Index extends \Magento\Backend\App\Action
  {
    /**
    * @var \Magento\Framework\View\Result\PageFactory
    */
    protected $resultPageFactory;

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

    /**
     * Load the page defined in view/adminhtml/layout/exampleadminnewpage_helloworld_index.xml
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
         return  $resultPage = $this->resultPageFactory->create();
    }
  }
?>

C:\xampp\htdocs\app\code\BBC\ProdAdmin\view\adminhtml\layout\ProdAdmin_index.xml

<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>
            Product Admin Access
        </title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Backend\Block\Template" template="BBC_ProdAdmin::AdminAccess.phtml"/>
        </referenceContainer>
    </body>
</page>

C:\xampp\htdocs\app\code\BBC\ProdAdmin\view\adminhtml\templates\AdminAccess.phtml

 <p>Hello World!</p>

And after these steps i get the below screen:Magento no data.png

Re: Data in custom admin module not showing up

You need to create xml file like below namespace,

C:\xampp\htdocs\app\code\BBC\ProdAdmin\view\adminhtml\layout\prodadmin_prodadmincontrol_index.xml

you have kept name Prodadmin_index.xml file. Please correct filename and clear cache and check,

If Issue Solved, Click Kudos/Accept As solutions.