Required file:
- app/code/{Vendor}/{ModuleName}/Controller/ControllerFolderInCamalCaseLetter/ActionFileNameInCamalCaseLetter.php
(Modified)
- app/code/{Vendor}/{ModuleName}/view/frontend/layout/
{RouteIdSmallLetter}_{ControllerFolderInSmallLetter}_{ActioNameInSmall}
.xml
Study Link
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-overview.html
app/code/{Vendor}/{ModuleName}/Controller/ControllerFolderInCamalCaseLetter/ActionFileNameInCamalCaseLetter.php
<?php
namespace {Vendor}\{ModuleName}\Controller\ControllerFolderInCamalCaseLetter;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
class ActionFileNameInCamalCaseLetter extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
{
public function __construct(
\Magento\Framework\App\Action\Context $context
) {
parent::__construct($context);
}
public function execute()
{
return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
}
}
Example
- File Path: app/code/StackExchange/Example/Controller/Index/Index.php
<?php
namespace StackExchange\Example\Controller\Index;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
class Index extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
{
public function __construct(
\Magento\Framework\App\Action\Context $context
) {
parent::__construct($context);
}
public function execute()
{
return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
}
}
- Layout file name format:
{RouteIdSmallLetter}_{ControllerFolderInSmallLetter}_{ActioNameInSmall}
.xml - RouteInSmallLetter: Get router id from here https://github.com/devamitbera/magento2-module-stucture/blob/master/2.Create-frontend-url.md#routesxml
- Example :
examples_index_index
.xml
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Your Page Title</title>
</head>
</page>
Example files:
- file name
examples_index_index.xml
**
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Example Page</title>
</head>
</page>
Your hit URL: http://domain.com/example/index/index
: The response comming like this: