ドクトリンでエンティティをサービスとして使用する方法 (Symfony 2.1 を使用)。
使用例:
<?php
namespace MyNamespace;
class MyEntity
{
protected $container = NULL;
public function __construct($container)
{
$this->container = $container;
}
/**
* @ORM\PrePersist
*/
public function()
{
// Must call to container and get any parameters
// for defaults sets entity parameters
$this->container->get('service.name');
}
}
その結果、コンテナ全体にアクセスする必要があります。