Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top