2

Hello,

I have create new custom module and run frontend get 404 Page error.

How to debug module what problem in code ?

Please Help me.

THANKS.

3
  • First thing which comes to my mind for 404 is routes check the routes for the module.
    – Tanmay
    Jul 16 '20 at 17:53
  • routes.xml file is well Jul 16 '20 at 18:12
  • share your routes.xml code along with your controller
    – Pramod
    Jul 17 '20 at 7:27
3

Check This Steps

Step-1 : First you need to check your module is enable or not.

Step-2 : You need to check are you working on right magento url or not.

Step-3 : Check your Route name in routes.xml app\code\VendoreName\ModuleName\etc\frontend

<?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="standard">
        <route frontName="yourroutename" id="yourroutename">
            <module name="VendoreName_ModuleName"/>
        </route>
    </router>
</config>

Step-4 : In above File must be there

Step-5 : Then create contoller (Index) app\code\VendoreName\ModuleName\Controller\Index

Step-6 : Add Action file like this (Index.php) at app\code\VendoreName\ModuleName\Controller\Index (Class Name and File Name must be same)

<?php

namespace VendoreName\ModuleName\Controller\Index;

use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Result\PageFactory;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $resultPageFactory;
    protected $customerSession;

    public function __construct(
        Context $context,
        PageFactory $resultPageFactory,
        Session $customerSession
    ) {
        $this->resultPageFactory = $resultPageFactory;
        $this->customerSession = $customerSession;
        parent::__construct($context);
    }

    public function execute()
    {
        return $this->resultPageFactory->create();
    }
}

Step-7 : Create layout for it in app\code\VendoreName\ModuleName\view\frontend\layout

Step-8 : Layout File name must be like this FrontendRouteName_FrontendControllerName_ActionFileName.xml

Step-9 : Add Blank Page layout like this

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">

    </referenceContainer>
</page>

Step-10 : Must be Run Magento Upgrade command before check in fronend.

Note: You can check and Compare your code with above code.

I Hope This helps You

1
  • i have already solve issues.but i think your code is right so +1 upvote. thanks.@Msquare Jul 17 '20 at 9:09

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.