Hier ist ein vollständiges Beispiel für die Funktionsweise der Fronted Route. Es handelt sich um eine Kombination aus Controller , Layout , Block und Vorlage .
Route
app / code / QaisarSatti / HelloWorld / etc / frontend / route.xml
<?xml version="1.0"?>
<!--
/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/-->
<config
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="helloworld" frontName="helloworld">
<module name="QaisarSatti_HelloWorld" />
</route>
</router>
</config>
Regler
app / code / QaisarSatti / HelloWorld / Controller / Index / Index.php
<?php
/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/
namespace QaisarSatti\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
}
}
Layoutdatei
app / code / QaisarSatti / HelloWorld / view / frontend / layout / helloworld_index_index.xml
<?xml version="1.0"?>
<!--
/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/-->
<page
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
layout="1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block
class="QaisarSatti\HelloWorld\Block\HelloWorld"
name="HelloWorld"
template="QaisarSatti_HelloWorld::HelloWorld.phtml">
.
</block>
</referenceContainer>
</body>
</page>
Vorlagendatei
app / code / QaisarSatti / HelloWorld / view / frontend / templates / HelloWorld.phtml
<?php
/**
* Catalog Product Rewrite Helper
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/
echo 'Hello World';
Benutzerdefinierter Block
app / code / QaisarSatti / HelloWorld / Block / HelloWorld.php
<?php
/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/
namespace QaisarSatti\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
public function _prepareLayout()
{
parent::_prepareLayout();
$this->pageConfig->getTitle()->set(__('First Hello World Module'));
return $this;
}
}
Referenz