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();
Amit Naraniwal
1,3081 gold badge11 silver badges20 bronze badges
asked Feb 27, 2019 at 7:11
9
  • have u create module.xml and registration.php? Commented Feb 27, 2019 at 7:15
  • please provide code of router.xml Commented Feb 27, 2019 at 7:16
  • Everything above looks correct, update your xml code into frontename_controllername_action.xml Commented Feb 27, 2019 at 7:16
  • Yes, I have created. Commented Feb 27, 2019 at 7:16
  • Please check code of route @AmitBera Commented Feb 27, 2019 at 7:18

2 Answers 2

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 :)

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

Change execute method of controller

public function execute()
 {
 $this->_view->loadLayout();
 $this->_view->getLayout()->initMessages();
 $this->_view->renderLayout();
 }
answered Feb 27, 2019 at 8:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.