Symfony form query_buider and entity repository

前端 未结 2 2014
梦谈多话
梦谈多话 2020-12-13 08:17

I\'m trying to create a form with data in collection type depending on the user being logged. I\'m following this chapter of the Symfony cookbook.

Everything works f

2条回答
  •  隐瞒了意图╮
    2020-12-13 08:42

    I just did a little fix of saamorim answer. The working code would be something like this:

    public function queryOwnedBy($user) {
    
        $query = $this->createQueryBuilder("u")
                ->where('u.id = :id')                
                ->setParameter('id', $user->getId());
    
        return $query;
    }
    
    public function findOwnedBy($user) {
        return $this->queryOwnedBy($user)
                ->getQuery()
                ->getResult();
    }
    

提交回复
热议问题