Skip to content

Commit

Permalink
Creacion de Modulo Mageplaza
Browse files Browse the repository at this point in the history
1.- ejemplo completo tomado de : https://www.mageplaza.com/magento-2-module-development/

Objetivo : crear una Pagina [vista] en el FRONTEND que cargue los registros de una tabla

Step 0: Create module
Step 1: Create routes.xml file
Step 2: Create controller file
Step 3: Create controller Layout file
Step 4: Create controller Block file
Step 5: Create controller template file
Step 6: Flush Magento cache
Step 7: Run a test new controller
  • Loading branch information
PerezContrerasLuis committed Jan 26, 2022
1 parent 01ff7b6 commit 16f8c38
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/Mageplaza/HelloWorld/Block/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Mageplaza\HelloWorld\Block;
class Index extends \Magento\Framework\View\Element\Template
{

}
20 changes: 20 additions & 0 deletions code/Mageplaza/HelloWorld/Controller/Index/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Mageplaza\HelloWorld\Controller\Index;

class Index 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();
}
}
21 changes: 21 additions & 0 deletions code/Mageplaza/HelloWorld/Controller/Index/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Mageplaza\HelloWorld\Controller\Index;

class Test 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()
{
echo "Hello World";
exit;
}
}
8 changes: 8 additions & 0 deletions code/Mageplaza/HelloWorld/etc/frontend/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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="hellomageplaza" id="hellomageplaza">
<module name="Mageplaza_HelloWorld"/>
</route>
</router>
</config>
5 changes: 5 additions & 0 deletions code/Mageplaza/HelloWorld/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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="Mageplaza_HelloWorld" setup_version="0.0.1">
</module>
</config>
6 changes: 6 additions & 0 deletions code/Mageplaza/HelloWorld/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mageplaza_HelloWorld',
__DIR__
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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="Mageplaza\HelloWorld\Block\Index" name="hellomageplaza_index_index" template="Mageplaza_HelloWorld::index.phtml" />
</referenceContainer>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>Welcome to Mageplaza.com</h2>
1 change: 1 addition & 0 deletions etc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
'Learning_HelloPage' => 1,
'Learning_Js' => 1,
'Luisdev_Helloworld' => 1,
'Mageplaza_HelloWorld' => 1,
'PayPal_Braintree' => 1,
'PayPal_BraintreeGraphQl' => 1,
'Pfay_Contacts' => 1,
Expand Down

0 comments on commit 16f8c38

Please sign in to comment.