如何在不传递参数的情况下获取存储库类中的容器对象? [英] How can I get container object in repository class without passing parameter?

查看:26
本文介绍了如何在不传递参数的情况下获取存储库类中的容器对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get container object in repository class without passing parameter?

推荐答案

你会得到如下容器对象:

You will get container object as follow:

// 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;
    }
}

谢谢

阿肖克·奇特罗达

这篇关于如何在不传递参数的情况下获取存储库类中的容器对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆