0

I have created a custom controller and die on controller execute page but it goes to 404 ?

COntroller file ( path : app/code/Mageplaza/HelloWorld/Controller/Index/helloworld.php )

<?php
namespace Mageplaza\HelloWorld\Controller\Index;

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

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $pageFactory)
{
    $this->_pageFactory = $pageFactory;
    return parent::__construct($context);
}

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

My helloworld_index_index.xml ( path : app/code/Mageplaza/HelloWorld/view/froentend/layout/helloworld_index_hello.xml )

<?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">
    <block class="Mageplaza\HelloWorld\Block\Index" name="helloworld_index_testcron" template="Mageplaza_HelloWorld::index.phtml" />
</referenceContainer>
</page>

my rotes.xml ( path : app/code/Mageplaza/HelloWorld/etc/froentend/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="standard">
    <route id="helloworld" frontName="helloworld">
        <module name="Mageplaza_HelloWorld" />
    </route>
</router>
</config>

I have hit http://127.0.0.1/projectname/helloworld/index/index but it goes to 404 Any help is appriciated

2
  • Please add your file path too.
    – Pratik Oza
    Commented Aug 20, 2020 at 19:16
  • Updated my file path please check @PratikOza
    – Prits
    Commented Aug 20, 2020 at 19:26

1 Answer 1

1

Wrong file path added in module. Update from froentend to frontend.

Also update controller path

From:

app/code/Mageplaza/HelloWorld/Controller/Index/helloworld.php

To:

app/code/Mageplaza/HelloWorld/Controller/Index/Index.php

For more detail, please refer to the link

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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