Answers:
假设您的模块在 Vendor\Module
如果你想捕捉从响应的HTML,你可以在你的声明事件etc\<area>\events.xml
(其中<area>
是adminhtml
或frontend
):
<?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="controller_front_send_response_before">
<observer name="vendor_module" instance="Vendor\Module\Model\Observer" shared="false" />
</event>
</config>
然后在Model\Observer.php
:
<?php
namespace Vendor\Module\Model;
use Magento\Framework\Event\ObserverInterface;
class Observer implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$response = $observer->getEvent()->getData('response');
if (!$response) return;
$body = $response->getBody();
}
}