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 8068865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:49:33+00:00 2026-06-05T12:49:33+00:00

I am trying to follow the Symfony2 cookbook tutorial for loading users from a

  • 0

I am trying to follow the Symfony2 cookbook tutorial for loading users from a DB.

The tutorial assumes you have a ACME/UserBundle and my installation doesn’t, but I just assumed I could make my own (it’s not like a plugin-packade I need to download somewhere right?).

I created a bundle UserBundle and copy-pasted the code from the tutorial’s entity User (first code box here).

This line seems to break things for me:

  @ORM\Entity(repositoryClass="Mycompany\UserBundle\Entity\UserRepository")

The error message I get is:

Fatal error: Class 'mycompany\UserBundle\Entity\UserRepository' not
found in /var/www/mycompany/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php
on line 578

So I either assume I couldn’t just create my own UserBundle (strange since I thought this was a tutorial on how to do it, not how to install a plugin that does it), or they assumed I knew that I somehow needed to register the entity among entityRepositories somehow?

I will be most grateful if anyone more senior in symfony would enlighten me on this. I truly love all that I have learned about Symfony2 so far, but I am a bit of a slow learner here.

  • 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-05T12:49:34+00:00Added an answer on June 5, 2026 at 12:49 pm

    It sounds like you dont have a user repository class, this is seperate to the user entity class. It goes in the entity folder but would be UserRepository.php and look something like:

    namespace Mycompany\UserBundle\Entity;
    
    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;
    use Doctrine\ORM\EntityRepository;
    use Doctrine\ORM\NoResultException;
    
    // Implements userproviderinterface so we can use the user entity for authentication
    // Extends entityrepository so that it gets methods definded there
    class UserRepository extends EntityRepository implements UserProviderInterface {
    
      //  This function is called when a user tries to login, the below lets the user use their username or email for username
      public function loadUserByUsername($username) {
        $user = $this->createQueryBuilder('u')
                ->select('u, r')
                ->leftJoin('u.roles', 'r')
                ->where('u.username = :username OR u.email = :username')
                ->setParameter('username', $username)
                ->getQuery();
        try {
          $user = $user->getSingleResult();
        } catch (NoResultException $exc) {
          throw new UsernameNotFoundException(sprintf('Unable to find an active UserBundle:User object identified by %s', $username));
        }
        return $user;
      }
      // 
      public function refreshUser(UserInterface $user) {
        $class = get_class($user);
        if (!$this->supportsClass($class))
          throw new UnsupportedUserException(sprintf('instances of class %s are not supported', $class));
        return $this->loadUserByUsername($user->getUsername());
      }
    
      public function supportsClass($class) {
        return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
      }
    
    }
    

    This class is available futher down the tutorial you are doing http://symfony.com/doc/current/cookbook/security/entity_provider.html

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

Sidebar

Related Questions

Trying to follow this tutorial, but my installation of mysql is failing. After getting
Trying to follow the hints laid out here , but she doesn't mention how
Trying to follow this tutorial. Autotest fails with this error message: sg $autotest loading
I'm trying to follow Michael Hartl's Ruby on Rails Tutorial in http://ruby.railstutorial.org/chapters/sign-in-sign-out , but
I'm trying to follow this tutorial - http://www.dotnetcurry.com/ShowArticle.aspx?ID=231&AspxAutoDetectCookieSupport=1 I have both the vsdoc file
I have been trying to follow this example from propel to configure a custom
I have been trying to follow this tutorial: http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ . It is to create
Trying to follow this MSDN tutorial to get a web response but not getting
Im trying to follow a tutorial that is using SBJsonParser to get twitter feeds,
I'm trying to follow along this tutorial to enable remote access to MySQL. The

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.