【问题标题】:Can't call entity functions from a returned repository query无法从返回的存储库查询中调用实体函数
【发布时间】:2011-11-30 06:37:27
【问题描述】:

我正在尝试使用我的实体类和存储库类之一从 symfony2 和教义中的数据库中获取对象。

这里是函数调用:

$game = $em->getRepository('MLBPBeerBundle:TableGame')->findBygameId($gid);
$game.setZoneTableid('20');

这是我的存储库类的 sn-p:

class TableGameRepository extends EntityRepository
{
public function findBygameId($gid)
{
    return $this->getEntityManager()
        ->createQuery('SELECT g FROM MLBPBeerBundle:TableGame g WHERE g.gameId = ' . $gid)
        ->getSingleResult();
}

这是我的实体类的 sn-p:

/**
 * MLBP\BeerBundle\Entity\TableGame
 *
 * @ORM\Table(name="table_game")
 * @ORM\Entity(repositoryClass="MLBP\BeerBundle\Repository\TableGameRepository")
 * 
 */
class TableGame
{
    /**
     * @var TableTable
     *
     * @ORM\ManyToOne(targetEntity="TableTable")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ZONE_TABLEID", referencedColumnName="TABLE_ID")
     * })
     */
        protected $zoneTableid;

    /**
     * Set zoneTableid
     *
     * @param MLBP\BeerBundle\Entity\TableTable $zoneTableid
     */
    public function setZoneTableid(\MLBP\BeerBundle\Entity\TableTable $zoneTableid)
    {
        $this->zoneTableid = $zoneTableid;
    }

这是我的错误信息:

调用未定义函数 MLBP\BeerBundle\Controller\setZoneTableid() 谢谢!

【问题讨论】:

    标签: php doctrine symfony


    【解决方案1】:

    请务必使用 -> 运算符而不是 .操作员。此外,对于这个特定示例,您不能将“20”设置为 zoneId,因为它不是表示 TableTable 的实体。

    $game->setZoneTableid(<Some Table Entity>);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      相关资源
      最近更新 更多