【发布时间】:2019-02-08 09:01:24
【问题描述】:
我在 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() 应该被调用 - 但事实并非如此。
怎么了?谁能告诉我?
【问题讨论】:
-
乍一看还不错。你清除缓存了吗?插件是否已安装并处于活动状态?
标签: plugins shopware subscriber