0

I created a Module and I am getting this 404 page error after I hit the submenu link. enter image description here

Here is the code. I can not figure out what is wrong.

acl.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="UpperLimits_QuantityToShip::parent" title="QuantityToShip" translate="title" sortOrder="30">
                    <resource id="UpperLimits_QuantityToShip::child" title="Child" translate="title" sortOrder="10">
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>


routes.xml --- in app/code/UpperLimits/QuantityToShip/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="productlisting" frontName="productlisting">
            <module name="UpperLimits_QuantityToShip"/>
        </route>
    </router>
</config>

menu.xml -- app/code/UpperLimits/QuantityToShip/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="UpperLimits_QuantityToShip::catalog_productlisting" title="Product Listing" module="UpperLimits_QuantityToShip" sortOrder="200" parent="Magento_Catalog::inventory" action="productlisting/product/index" resource="UpperLimits_QuantityToShip::product"/>
    </menu>
</config>


index php in --- app/code/UpperLimits/QuantityToShip/Controller/adminhtml/Product/index.php


<?php

namespace UpperLimits\QuantityToShip\Controller\Adminhtml\Product;
use Magento\Backend\App\Action;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\App\ResponseInterface;

class Index extends Action
{
  protected $_publicActions = ['index'];
  private $pageFactory;
  public function __construct(
    PageFactory $pageFactory,
    Action\Context $context)
  {
    $this->pageFactory = $pageFactory;
    parent::__construct($context);
  }
  public function execute()
  {
    return $this->pageFactory->create();
  }

      /**
     * IsAllowed go to this page
     *
     * @return bool
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('UpperLimits_QuantityToShip::parent');
    }
}

I am not sure what is wrong.

UPDATE: NOW I AM JUST GETTING A BANK WHITE PAGE, when I hit submenu link.

1

1

Please change directory name to camel case here app/code/UpperLimits/QuantityToShip/Controller/adminhtml/Product/index.php to app/code/UpperLimits/QuantityToShip/Controller/Adminhtml/Product/index.php .
adminhtml => Adminhtml.

When $this->pageFactory->create(); is executed from controller file it will look for a layout file. Add the layout file at view/adminhtml/layout/productlisting_product_index.xml with content similar to given below:

<?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">
    <referenceBlock name="page.title">
        <action method="setPageTitle">
            <argument name="title" xsi:type="string">Greetings</argument>
        </action>
    </referenceBlock>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Backend\Block\Template" template="UpperLimits_QuantityToShip::helloworld.phtml"/>
        </referenceContainer>
    </body>
</page>

Create template file at view/adminhtml/templates/helloworld.phtml with some test content like

<p>Hello World!</p>

Clear cache and it should work. If you are still facing issue please share complete controller code.

11
  • Actully, it did do something. I had to change the namespace path in my controller index.php file. namespace UpperLimits\QuantityToShip\Controller\Adminhtml\Product;. However, I am now getting this error and I dont know why. ` 1 exception(s): Exception #0 (InvalidArgumentException): Invalid return type Exception #0 (InvalidArgumentException): Invalid return type <pre>#1 Magento\Framework\App\Bootstrap->run(&Magento\Framework\App\Http\Interceptor#0000000078cc6a5d0000000036339049#) called at [index.php:39] </pre>` – Jonathan Sep 2 '20 at 16:01
  • I also updated the code files up top to show more. – Jonathan Sep 2 '20 at 16:28
  • Ok I believe pagefactory was being called wrong in the use Namespace. I changed it to use Magento\Framework\View\Result\PageFactory; But now I am just getting a blank white page. – Jonathan Sep 2 '20 at 16:37
  • Have you added layout and template file? Also enable developer mode and un-comment ini_set('display_errors', 1); in app/bootstrap.php file to see error on the screen. – amitshree Sep 3 '20 at 6:18
  • 1
    I have tested it. Make 2 changes in your module and it will work. 1) Change folder name adminhtml to Adminhtml inside Controller folder. 2) change template file name HelloWorld.phtml to helloworld.phtml (same name which is mentioned in layout file) – amitshree Sep 4 '20 at 20:48

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.