0

This is registration.php

<?php   

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE,'Mymodule_Newmodule1', __DIR__);

routes.xml file is here

<?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:App/etc/routes.xsd">
    <router id="standard">
        <route id="module1" frontName="module1">
            <module name="Mymodule_Newmodule1" />
        </route>
    </router>
</config>

Here is the controller file

<?php

namespace Mymodules\Newmodule1\Controller\Page;


class Helloworld 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()
    {
        echo "Hello world";
        exit;
    }
}

When i check in browser it show 404

My base url newsite.new1 newsite.new1/module1/page/helloworld returns 404

2
  • are you create module.xml file ?. Please check your module successfully installed or not via following command. php bin/magento module:status Mymodule_Newmodule1 – Singhe Jun 5 at 16:19
  • yes i created module.xml and it its enabled – pon aravind Jun 6 at 4:53
0

Try this below method.

https://devdocs.magento.com/videos/fundamentals/create-a-new-page/

Hope this is helpful.

2
  • do we need to give permission each time we create a module in linux – pon aravind Jun 6 at 5:15
  • No. after module created , you have to run these commands php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento cache:flush – Singhe Jun 6 at 5:56
0

Please create layout file for indentify controller url

create module1_page_helloworld.xml

and below is my code's example

<?xml version="1.0"?>
<!--
/**
 * @category   Rajesh 
 * @package    Rajesh_Gohil
 * @author     gohilrajesh92@gmail.com
 * @copyright  Rajesh Gohil
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Mymodules\Newmodule1\Block\ModuleBlock" name="view.template" template="view.phtml">
            </block>
        </referenceContainer>
    </body>
</page>

u need to also create block class and template for render layout in magento2

below is my block file

app/code/Mymodules/Newmodule1/Block/ModuleBlock.php

<?php
/**
 * @category   rajesh
 * @package    rajesh_gohil
 * @author     gohilrajesh92@gmail.com
 * @copyright  rajesh gohil
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Mymodules\Newmodule1\Block;

/**
 * Purchase content block
 */
class ModuleBlock xtends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
    }

    public function _prepareLayout()
    {
        $this->pageConfig->getTitle()->set(__('Module Title'));
        
        return parent::_prepareLayout();
    }
}

create phtml file also and add your code in phtml whatever you want to show on frontend.

app/code/Mymodules/Newmodule1/view/frontend/templates/view.phtml

<p>hello here</p>

hope this helps.

0

Guys i finally found solution thank you guys for answering i appreciate your help. The Problem is

my module is in app/code/Mymodules/Newmodule1 but i registered my module as Mymodule_Newmodule1 i missed the s

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.