1

Route

<?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="testproduct" frontName="testproduct">
            <module name="Test_Configureproduct" />
        </route>
    </router>
</config>

Block

    <?php                                                         
    namespace Test\Configureproduct\Block\Index;                      
    class ConfigureProductCollection extends \Magento\Framework\View\Element\Template                                  
    {
    public function __construct(\Magento\Framework\View\Element\Template\Context $context)
    {
        parent::__construct($context);
    }

    public function sayHello()
    {
        return __('Hello World');
    }
}

Controller

<?php                                                         
namespace Test\Configureproduct\Controller\Index;                 
class Configure 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();
}}

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="Test\Configureproduct\Block\Index\ConfigureProductCollection" name="configure_product_view" template="Test_Configureproduct::configure_product.phtml" />
</referenceContainer></page>

Template

<?php


echo $block->sayHello();
  • have u create module.xml and registration.php? – Amit Bera Feb 27 at 7:15
  • please provide code of router.xml – Amit Bera Feb 27 at 7:16
  • Everything above looks correct, update your xml code into frontename_controllername_action.xml – Prathap Gunasekaran Feb 27 at 7:16
  • Yes, I have created. – Masud Shaikh Feb 27 at 7:16
  • Please check code of route @AmitBera – Masud Shaikh Feb 27 at 7:18
2

Try this, To register a module you need to add

registration.php

<?php\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_Configureproduct',
__DIR__);

then create module.xml

etc/module.xml

<?xml version="1.0" ?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_Configureproduct" setup_version="1.0.0"/></config>

view/frontend/layout/testproduct_index_configure.xml

<?xml version="1.0" ?>                                            
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="content">
        <block class="Test\Configureproduct\Block\Index\Configure" name="index.configure" template="Test_Configureproduct::index/configure.phtml"/>
    </referenceContainer>
</body>                                                         
</page>

view/frontend/templates/index/configure.phtml

<?php echo "hello world"; ?>

etc/frontend/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 frontName="testproduct" id="testproduct">
        <module name="Test_Configureproduct"/>
    </route>
</router></config>

Controller/Index/Configure.php

<?php                                                         
namespace Test\Configureproduct\Controller\Index;                 
class Configure extends \Magento\Framework\App\Action\Action{

protected $resultPageFactory;

/**
 * Constructor
 *
 * @param \Magento\Framework\App\Action\Context  $context
 * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
 */
public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
    $this->resultPageFactory = $resultPageFactory;
    parent::__construct($context);
}

/**
 * Execute view action
 *
 * @return \Magento\Framework\Controller\ResultInterface
 */
public function execute()
{
    return $this->resultPageFactory->create();
}}

Block/Index/Configure.php

<?php                                                         
namespace Test\Configureproduct\Block\Index;                      
class Configure extends \Magento\Framework\View\Element\Template{

/**
 * Constructor
 *
 * @param \Magento\Framework\View\Element\Template\Context  $context
 * @param array $data
 */
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = []
) {
    parent::__construct($context, $data);
}}

Hope this helps :)

  • I have checked not created the block. – Masud Shaikh Feb 27 at 7:55
  • Is that hello world displayed in front or not? – Prathap Gunasekaran Feb 27 at 8:10
  • Not display hello world in front. – Masud Shaikh Feb 27 at 8:11
  • Check whether your module is installed or not? in app/etc/config.php – Prathap Gunasekaran Feb 27 at 8:12
  • Module is installed and URl also working fine URL: example.com/index.php/testproduct/index/configure IMG URL: ibb.co/xJQcd7y – Masud Shaikh Feb 27 at 8:13
0

Change execute method of controller

public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    }

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.