[英]how can I use shopware event-subscriber properly
I've created a custom plugin SwagStartup in Shopware, and it works by calling an url like "shopware.project/myDemo".我在Shopware中创建了一个自定义插件SwagStartup ,它通过调用像“shopware.project/myDemo”这样的 url 来工作。
Then I tried to define/use event subscriber in this plugin, following is the code:然后我尝试在这个插件中定义/使用事件订阅者,以下是代码:
<?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!');
}
}
And the XML file: Resources/services.xml:和 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>
When I called the url like before, I expected to see the output from the die() function, cause I thought the event Enlight_Controller_Action_PreDispatch should have been caught by the subscriber and the funciton onPreDispatch() should have been called - but it was not the case.当我像以前一样调用 url 时,我希望看到 die() 函数的输出,因为我认为事件Enlight_Controller_Action_PreDispatch应该被订阅者捕获并且函数 onPreDispatch()应该被调用 - 但它不是案件。
What's wrong?怎么了? Can someone tell me?有人可以告诉我吗?
I tried the same in a testplugin and it works fine: https://github.com/mnaczenski/SubscriberTest 我在一个testplugin中尝试了同样的方法,并且效果很好: https : //github.com/mnaczenski/SubscriberTest
It seems that your subscriber is not recognised. 看来您的订阅者未被识别。 Which shopware version do you use? 您使用哪个版本的商店软件?
Late reply but issue still valid with SW 6.4迟到的答复,但问题在 SW 6.4 中仍然有效
What I tried to do (And worked) was我尝试做的(并且有效)是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.