1

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

Magento Guide

My codes are :

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>

The result: enter image description here

  • I have updated your mistake check my answer. – Nikunj Vadariya May 24 '18 at 5:55
  • if my answer solves your concern then there is green right tick mark, hit that tickmark for right answer that will help future readers. – Nikunj Vadariya May 24 '18 at 5:57
  • Update file name composer.json instead of composer.jason and check. – Nits May 24 '18 at 5:57
0

Your layout looks wrong.

Try below:

../adminhtml/layout/prodadmin_prodadmincontrol_index.xml

<body>
    <referenceBlock name="page.main.title" remove="true" />
    <referenceContainer name="content">
        <block class="BBC\ProdAdmin\Block\Adminhtml\Test" name="test" template="AdminAccess.phtml" />
    </referenceContainer>
</body>

../Block/Adminhtml/Test.php

namespace BBC\ProdAdmin\Block\Adminhtml;

class Test extends \Magento\Framework\View\Element\Html\Link
{
  // Your Functions
}

../templates/AdminAccess.phtml

<?php  echo "Today is " . date("Y/m/d") . "<br>"; ?>
  • Should I recompile magento – neelav barai May 24 '18 at 5:58
  • Yes, Execute setup:upgrade from root of Magento. – TBS Mage May 24 '18 at 6:05
  • I got Below error – neelav barai May 24 '18 at 6:36
  • @neelavbarai, As i said above execute php bin/magento setup:upgrade . than cache:clean than check. – TBS Mage May 24 '18 at 7:00
0

You are doing wrong.

I have just created the same module and its working for me.

  1. composer.json, registration.php, etc/module.xml, etc\adminhtml\routes.xml and Controller\Adminhtml\ProdAdminControl\Index.php file looks okay.

I have update below the files.

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>

BBC/ProdAdmin/view/adminhtml/layout/prodadmin_prodadmincontrol_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>

BBC/ProdAdmin/view/adminhtml/templates/adminaccess.phtml

AdminAccess.phtml replace with adminaccess.phtml

php bin/magento cach:flush

Now your module is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.