Question

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

Was it helpful?

Solution

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

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