簡體   English   中英

我如何正確使用 shopware event-subscriber

[英]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 中仍然有效

我嘗試做的(並且有效)是

  1. 從訂閱者服務中刪除該類。 留下id就行
  2. 將 <tag 移到參數上方

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM