Php 将事件记录到Symfony中的数据库

Php 将事件记录到Symfony中的数据库,php,symfony,Php,Symfony,我遵循了这个指南: 我做了除第二步以外的所有步骤,因为我不需要这些信息 错误: Whoops, looks like something went wrong. 1/1 ClassNotFoundException in CompanySubscriber.php line 19: Attempted to load class "CompanyEvent" from namespace "AppBundle\Events". Did you forget a "use" statement f

我遵循了这个指南:

我做了除第二步以外的所有步骤,因为我不需要这些信息

错误:

Whoops, looks like something went wrong.
1/1 ClassNotFoundException in CompanySubscriber.php line 19: Attempted to load class "CompanyEvent" from namespace "AppBundle\Events".
Did you forget a "use" statement for another namespace?

in CompanySubscriber.php line 19
at CompanySubscriber::getSubscribedEvents() in classes.php line 3361
at ContainerAwareEventDispatcher->addSubscriberService('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')
at call_user_func_array(array(object(ContainerAwareEventDispatcher), 'addSubscriberService'), array('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')) in TraceableEventDispatcher.php line 227
at TraceableEventDispatcher->__call('addSubscriberService', array('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')) in appDevDebugProjectContainer.php line 660
at appDevDebugProjectContainer->getDebug_EventDispatcherService() in classes.php line 3090
at Container->get('debug.event_dispatcher') in appDevDebugProjectContainer.php line 4175
at appDevDebugProjectContainer->getSecurity_Authentication_ManagerService() in appDevDebugProjectContainer.php line 2554
at appDevDebugProjectContainer->getSecurity_AuthorizationCheckerService() in classes.php line 3090
at Container->get('security.authorization_checker', 2) in appDevDebugProjectContainer.php line 3596
at appDevDebugProjectContainer->getTwigService() in classes.php line 3090
at Container->get('twig') in appDevDebugProjectContainer.php line 501
at appDevDebugProjectContainer->getCacheWarmerService() in classes.php line 3090
at Container->get('cache_warmer') in Kernel.php line 499
at Kernel->initializeContainer() in Kernel.php line 116
at Kernel->boot() in Kernel.php line 165
at Kernel->handle(object(Request)) in app_dev.php line 30
服务.yml

parameters:
services:
    monolog.db_handler:
        class: AppBundle\Util\MonologDBHandler
        arguments: ['@doctrine.orm.entity_manager']
    appbundle.subscriber.abstract_subscriber:
        class: AppBundle\EventSubscriber\AbstractSubscriber
        arguments: ['@service_container']

    appbundle.subscriber.company_subscriber:
        class: AppBundle\EventSubscriber\CompanySubscriber
        parent: appbundle.subscriber.abstract_subscriber
        tags:
            - { name: kernel.event_subscriber }
CompanyEvent.php

<?php

namespace AppBundle\Events;

/**
 * Class CompanyEvent
 * @package AppBundle\Events
 */
class CompanyEvent extends AbstractEvent
{
    const COMPANY_ADDED = 'company_added';
}

订阅者找到了您公司的subscriber类,并对其进行了实例验证,没有出现任何问题,也没有出现编写器问题。请查看
AppBundle\Events
的路径,必须是
。/src/AppBundle/Events/CompanyEvent.php
,查看文件名、大小写等

很抱歉出现问题

我反复检查了所有的路径、用途、类等,结果都不起作用


然后我更新了symfony(没有注意到具体更新了什么),但它开始工作了,所以问题就解决了。

你能添加你的作曲家json吗?至少自动加载部分认为它与composer.json file.Hm无关。它变得越来越陌生。我创建了一个名为BozahEvent的新类,它成功了。P.s.I双重、三重检查所有名称和路径。他们都是对的。
<?php

namespace AppBundle\EventSubscriber;

use AppBundle\Events\CompanyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Class CompanySubscriber
 * @package AppBundle\EventSubscriber
 */
class CompanySubscriber extends AbstractSubscriber implements EventSubscriberInterface
{
    /**
     * @return array
     */
    public static function getSubscribedEvents() {
        return [
            CompanyEvent::COMPANY_ADDED => 'onCompanyAdded',
        ];
    }

    /**
     * @param CompanyEvent $event
     */
    public function onCompanyAdded(CompanyEvent $event) {
        $this->logEntity(CompanyEvent::COMPANY_ADDED, [
            'Company' => $event->getEntity()->getCompany()
        ]);
    }

}