将 knplas 学说行为中的 loggable 与日志表一起使用 [英] Using loggable from knplabs doctrine behaviors with log table
问题描述
我在一个新的 symphony2 项目上设置了 KnpLabs Doctrine Behaviors,我需要实现 loggable 在我的数据库上记录实体更改的行为.
I've setuped KnpLabs Doctrine Behaviors on a new symphony2 project, and I need to implement the loggable behavior to log entities' changes on my database.
基于这个例子:https://github.com/KnpLabs/DoctrineBehaviors/issues/96,这是我所做的:
Based on this example : https://github.com/KnpLabs/DoctrineBehaviors/issues/96, here is what I've done :
服务:knp.doctrine_behaviors.loggable_subscriber.logger_callable:类:acme\MyBundle\DatabaseLogger\DatabaseLogger参数:['@doctrine.entity_manager']
命名空间 acme\MyBundle\DatabaseLogger;使用 Symfony\Component\HttpKernel\Log\LoggerInterface;使用 acme\MyBundle\Entity\Log;类 DatabaseLogger{私人 $em;公共函数 __construct(EntityManager $em){$this->em = $em;}公共函数 __invoke($message){$this->em->persist(new Log($message));$this->em->flush();}}
你知道为什么它不起作用吗?
Do you have any idea why it isn't working ?
推荐答案
事实上,我的问题有点不同,我忘记将我的 bundle 的 services.yml 导入到我的/app/config/config.yml 文件中:-S:
In fact, my problem was a little different, I've forgotten to import my bundle's services.yml into my /app/config/config.yml file :-S :
导入:- { 资源:@acmeMyBundle/Resources/config/services.yml }
从这一点来说,我的 DatabaseLogger 被调用而不是标准的 LoggerCallable
From this point, my DatabaseLogger is called instead of the standard LoggerCallable
这篇关于将 knplas 学说行为中的 loggable 与日志表一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!