magento2
Evénement et observateur dans magento 2
Recherche…
Comment utiliser un événement et un observateur personnalisés?
Étape 1: Créez le fichier events.xml
en fonction de vos besoins en frontend
, Backend
ou à la fois YKM/Banner/etc/frontend/events.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="controller_action_predispatch">
<observer name="ykm_banner_before" instance="YKM\Banner\Observer\Help" />
</event>
</config>
Étape 2:
Créer un fichier Observer YKM/Banner/Observer/Help.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Estdevs\Banner\Observer;
use Magento\Framework\Event\ObserverInterface;
class Help implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer) {
echo "this is good.";
}
}
Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow