我编写了一个显示系统所有管理员的页面。我想要做的是自定义我的查询,以便它将当前经过身份验证的用户从列表中排除。
现在我知道我可以user_id
从控制器获取并将其传递给实体存储库,但我想知道是否有办法直接通过实体存储库访问它?
例如:
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
class AdminUserRepository extends EntityRepository implements UserProviderInterface
{
public function getAdmins($int = 10, $offset = 0, array $orderBy = array('admin_id', 'asc')){
$admin_id = fetch the admin id ?;
$query = $this->createQueryBuilder('admins')
->where("admins.admin_id != '".$admin_id."'")
->orderBy('admins.'.$orderBy[0], $orderBy[1])
->setFirstResult($offset)
->setMaxResults($int)
->getQuery()
->getResult();
return $query;
}
}