[英]how can I use shopware event-subscriber properly
我在Shopware中创建了一个自定义插件SwagStartup ,它通过调用像“shopware.project/myDemo”这样的 url 来工作。
然后我尝试在这个插件中定义/使用事件订阅者,以下是代码:
<?php
namespace SwagStartup\Subscriber;
use Enlight\Event\SubscriberInterface;
class RoutingSubscriber implements SubscriberInterface
{
public static function getSubscribedEvents(){
return ['Enlight_Controller_Action_PreDispatch' => 'onPreDispatch'];
}
public function onPreDispatch(\Enlight_Event_EventArgs $args){
die('here!');
}
}
和 XML 文件:Resources/services.xml:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="swag_startup.subscriber.routing_subscriber"
class="SwagStartup\Subscriber\RoutingSubscriber">
<tag name="shopware.event_subscriber"/>
</service>
</services>
</container>
当我像以前一样调用 url 时,我希望看到 die() 函数的输出,因为我认为事件Enlight_Controller_Action_PreDispatch应该被订阅者捕获并且函数 onPreDispatch()应该被调用 - 但它不是案件。
怎么了? 有人可以告诉我吗?
我在一个testplugin中尝试了同样的方法,并且效果很好: https : //github.com/mnaczenski/SubscriberTest
看来您的订阅者未被识别。 您使用哪个版本的商店软件?
迟到的答复,但问题在 SW 6.4 中仍然有效
我尝试做的(并且有效)是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.