gpt4 book ai didi

php - 如何在 Doctrine2/Symfony2 的存储库中获取外部存储库?

转载 作者:IT王子 更新时间:2023-10-28 23:49:50 26 4
gpt4 key购买 nike

我需要来自 2 个不同实体的值。我不知道该怎么做。到目前为止我尝试过这个:

<?php

namespace Pond\GeolocBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
* PondLakeRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class PondLakeRepository extends EntityRepository
{

public function getSwimsAvailableById($id)
{
// get the nb of swims of a lake
$lake = $this->findOneById($id);
$swims = $lake->getSwims();

$repository = $this->getDoctrine()
->getManager()
->getRepository('PondGeolocBundle:User_Lake');

//get the nb of users in a lake
$qb = $this->_em->createQueryBuilder();
$qb->select('count(a.id)');
$qb->from('PondGeolocBundle:User_Lake', 'a');

$nbOfUsers = $qb->getQuery()->getSingleScalarResult();

// return the nb of swims available onthis lake
$avail = $swims - $nbOfUsers;
print_r ($avail);
}

}

不起作用请帮忙。谢谢

最佳答案

您可以通过调用 Doctrine\ORM\EntityRepository#getEntityManager() 访问 EntityManager :

$repository = $this
->getEntityManager()
->getRepository('PondGeolocBundle:User_Lake');

关于php - 如何在 Doctrine2/Symfony2 的存储库中获取外部存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15466513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com