Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:42:38+00:00 2026-06-15T11:42:38+00:00

I have coded a page which displays all administrators of the system. What I

  • 0

I have coded a page which displays all administrators of the system. What I want to do is customize my query so that it would exclude the currently authenticated user from the list.
Now I know I can get the user_id from the controller and pass it to the entity repository, but I was wondering if there is a way to access that directly through the Entity Repository?

For example:

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;
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:42:39+00:00Added an answer on June 15, 2026 at 11:42 am

    So, you have a current User ID (let’s say, $currentUserId), and you want to write a query for all Users with an ID that is not equal to $currentUserId?

    Try this:

    class SomeController
    {
        public function someAction()
        {
            ...
    
            $qb = $userRepository->createQueryBuilder("user")
                ->where("user.id != ?1")
                ->setParameter(1, $currentUserId);
    
            $usersExcludingCurrent = $qb->getQuery()->getResult();
    
        ...
        }
    }
    

    edit

    Ahh, I see what you’re saying…

    Well, the repository really should be blind to anything outside of itself. That is, it’s not container-aware, and should therefore not know who the current user is.

    My suggestion would be to give your repository a function that gets everything except for a particular User or User ID. Something like:

    class AdminUserRepository extends EntityRepository implements UserProviderInterface
    {
        public function getAllAdminsExcept($userId, $int = 10, $offset = 0, array $orderBy = array('admin_id', 'asc'))
            {
                ...
            }
    }
    

    And then put the “current User” logic into your controller. You could even define a service that has access to both @security and @doctrine, and house all the logic there. Your call, but I’d say that you should definitely keep your repository unaware of anything going on in the security service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have a quote page which lists all existing quotes that we would
I have a multilingual website and. Htaccess, which displays all the pages. I want
I have my php coded page on one server that returns a json result.
I have a web page, let's call it main.php which displays an image of
I have the following code which displays the user's zipcode on the page (if
Have a simple page that pulls results from MySQL and displays them in a
I have a page on a training site which displays several downloads whose ids
I have an .aspx page which displays info from a database and lets users
I have a master page in which I have the following code. <head runat=server>
I have a page which has many event handlers. The code now reached 1000+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.