使用来自knplabs doctrine行为的loggable和日志表

时间:2014-10-31 09:55:09

标签: symfony

我已经在一个新的symphony2项目上设置了KnpLabs Doctrine Behaviors,我需要实现loggable行为来记录我的数据库中实体的更改。

基于这个例子:https://github.com/KnpLabs/DoctrineBehaviors/issues/96,这就是我所做的:

/acme/MyBundle/Ressources/config/services.yml:

services: knp.doctrine_behaviors.loggable_subscriber.logger_callable: class: acme\MyBundle\DatabaseLogger\DatabaseLogger arguments: ['@doctrine.entity_manager']

/acme/MyBundle/DatabaseLogger\DatabaseLogger.php:

namespace acme\MyBundle\DatabaseLogger; use Symfony\Component\HttpKernel\Log\LoggerInterface; use acme\MyBundle\Entity\Log; class DatabaseLogger { private $em; public function __construct(EntityManager $em) { $this->em = $em; } public function __invoke($message) { $this->em->persist(new Log($message)); $this->em->flush(); } }

你知道它为什么不起作用吗?

1 个答案:

答案 0 :(得分:0)

事实上,我的问题有点不同,我忘记将我的软件包的services.yml导入到我的/app/config/config.yml文件中:-S:

imports: - { resource: @acmeMyBundle/Resources/config/services.yml }

从这一点开始,我的DatabaseLogger被调用而不是标准的LoggerCallable