我有一个用Symfony2编码的应用程序。我已经创建了一个Account实体,并使用批注创建了一个名为AccountRepository的存储库,并在AccountRepository对象内部创建了一个函数,该函数可以运行一些业务逻辑,该逻辑将发送给外部供应商并在其站点上创建用户,并将信息返回给我们,这样我就可以将他们的用户与我们的帐户实体相关联。创建该用户的一部分包括通过信用卡 token 发送。然后,他们返回一些我想存储并与我们的帐户关联的有限的信用卡数据,因此在创建对象并插入适当的数据后,我拥有一个实体AccountCard,我无法从存储库中请求实体管理器并继续执行该操作$ em变量上的print_r没有显示任何内容,但是我读过的所有内容都告诉我应该可以做到这一点。我究竟做错了什么?

<?php

namespace Openbridge\CommonBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

use Openbridge\CommonBundle\Entity\Account as Account;
use Openbridge\CommonBundle\Entity\AccountCard as AccountCard;
use Openbridge\CommonBundle\Entity\AccountAddress 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使用该构造函数将依赖项绑定(bind)到类。

关于php - 教义存储库getEntityManager()确实返回空,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18067599/

10-11 23:57
查看更多