Skip to content

Commit

Permalink
Controlador y sus Acciones
Browse files Browse the repository at this point in the history
1.- creación y registro de nuestro modulo
	app/code/Pfay/Contacts/etc/module.xml
	app/code/Pfay/Contacts/registration.php
	Mas info de como crear un modulo : 7c3a945
2.- Creamos nuestro controlador Index:
	app/code/Pfay/Contacts/Controller/Test/Index.php
	OJO => LA CLASE CON NOMBRE INDEX para MAGENTO2 en realidad ES UNA ACCION
	en Magento 2 se tiene que crear un archivo por acción y tendrá que extender de la clase : ACTION.
	SIEMPRE tendrá que contar con el método EXECUTE().
3.- Creamos la ruta para acceder a nuestro controlador:
	app/code/Luisdev/Helloworld/etc/frontend/routes.xml
	el nombre que se le asigno en la etiqueta FRONTNAME será el que usaremos en la ruta URL del navegador
	a la cual accedemos asi :
	http://magento240.local/contacts/test/index
	o tambien así:
	http://magento240.local/contacts/test/
4.- Creamos otro ejemplo de acción para nuestro controlador
	app/code/Pfay/Contacts/Controller/Test/View.php
	a la cual accedemos asi :
	http://magento240.local/contacts/test/view
5.- Finalmente activamos y actualizamos y recompilamos
	php bin/magento setup:upgrade
	php bin/magento setup:di:compile
	chmod -R 777 var/ pub/

	grep Pfay_Contacts app/etc/config.php
  • Loading branch information
PerezContrerasLuis committed Jan 19, 2022
1 parent 3569e15 commit f693d0c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions code/Pfay/Contacts/Controller/Test/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Pfay\Contacts\Controller\Test;
class Index extends \Magento\Framework\App\Action\Action
{
public function execute()
{
die('test index');
}
}
9 changes: 9 additions & 0 deletions code/Pfay/Contacts/Controller/Test/View.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Pfay\Contacts\Controller\Test;
class View extends \Magento\Framework\App\Action\Action
{
public function execute()
{
die('test index View');
}
}
8 changes: 8 additions & 0 deletions code/Pfay/Contacts/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 id="contacts" frontName="contacts">
<module name="Pfay_Contacts" />
</route>
</router>
</config>
8 changes: 8 additions & 0 deletions code/Pfay/Contacts/etc/module.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:Module/etc/module.xsd">
<module name="Pfay_Contacts" setup_version="2.0.0">
<sequence>
<module name="Magento_Cms"/>
</sequence>
</module>
</config>
7 changes: 7 additions & 0 deletions code/Pfay/Contacts/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Pfay_Contacts',
__DIR__
);
1 change: 1 addition & 0 deletions etc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
'Luisdev_Helloworld' => 1,
'PayPal_Braintree' => 1,
'PayPal_BraintreeGraphQl' => 1,
'Pfay_Contacts' => 1,
'Temando_ShippingRemover' => 1,
'Vertex_Tax' => 1,
'Vertex_AddressValidation' => 1,
Expand Down

0 comments on commit f693d0c

Please sign in to comment.