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
Masud Shaikh
1,19922 silver badges55 bronze badges
-
have u create module.xml and registration.php?Amit Bera– Amit Bera ♦2019年02月27日 07:15:54 +00:00Commented Feb 27, 2019 at 7:15
-
please provide code of router.xmlAmit Bera– Amit Bera ♦2019年02月27日 07:16:26 +00:00Commented Feb 27, 2019 at 7:16
-
Everything above looks correct, update your xml code into frontename_controllername_action.xmlPrathap Gunasekaran– Prathap Gunasekaran2019年02月27日 07:16:28 +00:00Commented Feb 27, 2019 at 7:16
-
Yes, I have created.Masud Shaikh– Masud Shaikh2019年02月27日 07:16:29 +00:00Commented Feb 27, 2019 at 7:16
-
Please check code of route @AmitBeraMasud Shaikh– Masud Shaikh2019年02月27日 07:18:49 +00:00Commented Feb 27, 2019 at 7:18
2 Answers 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
Prathap Gunasekaran
3,2891 gold badge17 silver badges39 bronze badges
-
I have checked not created the block.Masud Shaikh– Masud Shaikh2019年02月27日 07:55:24 +00:00Commented Feb 27, 2019 at 7:55
-
Is that hello world displayed in front or not?Prathap Gunasekaran– Prathap Gunasekaran2019年02月27日 08:10:32 +00:00Commented Feb 27, 2019 at 8:10
-
Not display hello world in front.Masud Shaikh– Masud Shaikh2019年02月27日 08:11:47 +00:00Commented Feb 27, 2019 at 8:11
-
Check whether your module is installed or not? in app/etc/config.phpPrathap Gunasekaran– Prathap Gunasekaran2019年02月27日 08:12:17 +00:00Commented 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/xJQcd7yMasud Shaikh– Masud Shaikh2019年02月27日 08:13:20 +00:00Commented Feb 27, 2019 at 8:13
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
user68317
default