我已经在一个新的symphony2项目上设置了KnpLabs Doctrine Behaviors,我需要实现loggable行为来记录我的数据库中实体的更改。
基于这个例子:https://github.com/KnpLabs/DoctrineBehaviors/issues/96,这就是我所做的:
services:
knp.doctrine_behaviors.loggable_subscriber.logger_callable:
class: acme\MyBundle\DatabaseLogger\DatabaseLogger
arguments: ['@doctrine.entity_manager']
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();
}
}
你知道它为什么不起作用吗?
答案 0 :(得分:0)
事实上,我的问题有点不同,我忘记将我的软件包的services.yml导入到我的/app/config/config.yml文件中:-S:
imports:
- { resource: @acmeMyBundle/Resources/config/services.yml }
从这一点开始,我的DatabaseLogger被调用而不是标准的LoggerCallable