php – Doctrine Repository getEntityManager()确实返回空
发布时间:2020-12-13 17:25:06 所属栏目:PHP教程 来源:网络整理
导读:我有一个我用Symfony2编写的应用程序.我创建了一个Account实体,并使用注释创建了一个名为AccountRepository的存储库.在AccountRepository对象中,我创建了一个函数来运行一些业务逻辑,该逻辑传递给外部供应商并在其站点上创建用户,并返回信息对我们来说,我可
我有一个我用Symfony2编写的应用程序.我创建了一个Account实体,并使用注释创建了一个名为AccountRepository的存储库.在AccountRepository对象中,我创建了一个函数来运行一些业务逻辑,该逻辑传递给外部供应商并在其站点上创建用户,并返回信息对我们来说,我可以将他们的用户与我们的帐户实体相关联.创建该用户的一部分包括通过信用卡令牌发送.然后,他们返回我想存储的一些有限的信用卡数据并与我们的帐户关联,因此在创建对象并插入适当的数据后,我有一个实体AccountCard,我无法从存储库请求实体管理器并保持AccountCard执行$em变量上的print_r什么也没有显示,但我读过的所有内容都告诉我,我应该能够做到这一点.我究竟做错了什么?
<?php namespace OpenbridgeCommonBundleEntityRepository; use DoctrineORMEntityRepository; use OpenbridgeCommonBundleEntityAccount as Account; use OpenbridgeCommonBundleEntityAccountCard as AccountCard; use OpenbridgeCommonBundleEntityAccountAddress as AccountAddress; /** * AccountRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ class AccountRepository extends EntityRepository { public function __construct() { } function createVendorUser(Account $account,$userData = array()) { // Request new user from vendor code here. (this works) $ac = new AccountCard(); // setters for $ac data here. // Get entity manager $em = $this->getEntityManager(); $em->persist($ac); $em->flush(); } 解决方法
您必须删除构造函数,因为
EntityRepository使用它来将依赖项绑定到类.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |