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

Chi*_*ani 1 symfony

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

Ash*_*oda 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Ashok Chitroda