I would like to create own controller with own frontend view.
Here are my files: registration.php:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Unity_CheckOrder',
__DIR__
);
controller:
namespace Unity\CheckOrder\Controller\Index;
//use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
// protected $_resultPageFactory;
//
// public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
// {
// $this->_resultPageFactory = $resultPageFactory;
// parent::__construct($context);
// }
public function execute()
{
echo '<p>You Did It!</p>';
var_dump(__METHOD__);
// $resultPage = $this->_resultPageFactory->create();
// $resultPage->addHandle('check_order');
// return $resultPage;
}
}
Of course I tried also with:
namespace Unity\CheckOrder\Controller\Index;
use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_resultPageFactory;
public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
{
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
// echo '<p>You Did It!</p>';
// var_dump(__METHOD__);
$resultPage = $this->_resultPageFactory->create();
$resultPage->addHandle('check_order');
return $resultPage;
}
}
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="Unity_CheckOrder" setup_version="1.0.0">
</module>
</config>
etc/frontend/routes.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="checkorder" frontName="checkorder">
<module name="Unity_CheckOrder" />
</route>
</router>
</config>
view/frontend/layout/checkorder_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" layout="1column">
<head>
<title>
Simple Magento 2 Module
</title>
</head>
<body>
<referenceContainer name="content">
<block class="Unity\CheckOrder\Block\Test" name="checkorder" template="Unity_CheckOrder::checkorder.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
view/frontend/templates/checkorder.phtml
<?php $this->getHelloWorldTxt(); ?>
block test.php
<?php
namespace Unity\CheckOrder\Block;
class Test extends \Magento\Framework\View\Element\Template
{
public function __construct(\Magento\Backend\Block\Template\Context $context, array $data = [])
{
parent::__construct($context, $data);
}
public function getHelloWorld()
{
return 'Hello World';
}
}
I also tried with
<?php
namespace Unity\CheckOrder\Block;
class Test extends \Magento\Framework\View\Element\Template
{
public function getHelloWorld()
{
return 'Hello World';
}
}
After go to url magento2test.localhost/checkorder/ and magento2test.localhost/checkorder/index/index/
I got 404 all the time. Of course I tried :
php bin/magento setup:upgrade
rm -rf var/cache/* var/page_cache/* var/generation/*
php bin/magento cache:clean / flush
php bin/magento indexer:reindex
php bin/magento setup:di:compile
Module is enabled and visible in Admin Advanced tab
http://localhost/checkorder/
? You should try with ` localhost/yourmagento/checkorder`router.php
controller?