Skip to content

Commit

Permalink
Creacion de Evento
Browse files Browse the repository at this point in the history
1.- creamos nuestro controlador Myevent , aqui tenemos el evento dispacth que activa el vento registrado en events.xml
2.- creamos nuestro evento events.xml el cual declara un observador  llamado TestObserver
3.- creamos nuestro Observador
  • Loading branch information
PerezContrerasLuis committed Jan 24, 2022
1 parent 2d443be commit d0ead53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions code/Pfay/Contacts/Controller/Test/Myevent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Pfay\Contacts\Controller\Test;

use Magento\Framework\App\Action\Action;

class Myevent extends Action
{
public function execute()
{

$this->_eventManager->dispatch('pfay_contacts_event_test');
die('test');
}
}
20 changes: 20 additions & 0 deletions code/Pfay/Contacts/Observer/TestObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Pfay\Contacts\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

/**
* Class TestObserver
*/
class TestObserver implements ObserverInterface
{

/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
die('test observer');
}
}
6 changes: 6 additions & 0 deletions code/Pfay/Contacts/etc/frontend/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="pfay_contacts_event_test">
<observer name="pfay_contacts_observer_test" instance="Pfay\Contacts\Observer\TestObserver" />
</event>
</config>

0 comments on commit d0ead53

Please sign in to comment.