symfony easyadmin query_builder静态方法注入token_storage

时间:2018-09-13 09:25:12

标签: symfony easyadmin

我使用symfony 3.4和easycorp / easyadmin-bundle 1.17

我正在尝试将静态函数用于query_builder选项:

form:
    fields:
        ...
        - { property: 'customer', label: '', type_options: { query_builder: ['AppBundle\Repository\PersonRepository', 'getCustomer'] } }

存储库:

class PersonRepository extends EntityRepository
{
    public static function getCustomer(EntityRepository $er)
    {
        //        dump($tokeStorage);
        dump($er);
        die;
        $user = null; // how to get token_storage ?
        $query = $er->createQueryBuilder('person')
            ->leftJoin('person.userCreated', 'user')
            ->andWhere('person.type = :type')
            ->setParameter('type', 2)
        ;
        if (in_array("ROLE_ADMIN", $user->getRoles())) {
            $query->andWhere('user.company = :company');
            $query->setParameter('company', $user->getCompany());
        } else {
            $query->andWhere('user.id = :user');
            $query->setParameter('user', $user->getId());
        }

        return $query;
    }
}

我需要注入令牌存储,怎么办?

我打开了3个围绕该主题的帖子,或者我认为“静态”解决方案不是一个好方法,但是这3个解决方案都没有给我预期的结果

[symfony easyadmin custom form builder

[symfony easyadmin form field type entity with filter list

预先感谢

0 个答案:

没有答案