加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

symfony – get(‘doctrine’)之间的区别;和getDoctrine();

发布时间:2020-12-15 04:23:18 所属栏目:Java 来源:网络整理
导读:在Symfony中,我找到了三种访问doctrine服务和实体管理器的方法,如下所示: $em = $this-getDoctrine()-getManager();$em = $this-get('doctrine')-getEntityManager();$em = $this-container-get('doctrine.orm.entity_manager'); 任何人都可以请他们解释他
在Symfony中,我找到了三种访问doctrine服务和实体管理器的方法,如下所示:

$em = $this->getDoctrine()->getManager();

$em = $this->get('doctrine')->getEntityManager();

$em = $this->container->get('doctrine.orm.entity_manager');

任何人都可以请他们解释他们的分歧,并解释我们何时应该使用其中的哪一个.

解决方法

第一个仅在扩展基本控制器时可用.这是执行$this-> get(‘doctrine’)的捷径,你可以看到 in the source:

public function getDoctrine()
{
    if (!$this->container->has('doctrine')) {
        throw new LogicException('The DoctrineBundle is not registered in your application.');
    }

    return $this->container->get('doctrine');
}

$this-> get(‘doctrine’)也只能在控制器中使用. get也在基本控制器中定义,是$this-> container-> get()的快捷方式:

public function get($id)
{
    return $this->container->get($id);
}

$this-> container-> get(‘doctrine’)是获取学说注册表的完整书面形式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读