如何在不传递参数的情况下在存储库类中获取容器对象?

时间:2014-03-26 14:10:57

标签: symfony

  

如何在不传递的情况下在存储库类中获取容器对象   参数β

1 个答案:

答案 0 :(得分:5)

您将获得容器对象,如下所示:

// include files to get container
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class ClassNameRepository extends EntityRepository implements ContainerAwareInterface
{
    /**
     * @var ContainerInterface
     *
     * @author Ashok Chitroda <ashok.chitroda@gmail.com>
     */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
}

由于

Ashok Chitroda