0

I'd like to use the Fos UserBundle in Symfony.

I've configure it like "Getting Started With FOSUserBundle" from Symfony Doc.

The /Login Page is working but when I open the /register Page I get the Error:

Attempted to load class "User" from namespace "AppBundle\Entity". Did you forget a "use" statement for e.g. "Symfony\Component\Security\Core\User\User", "Symfony\Bridge\Doctrine\Tests\Fixtures\User" or "FOS\UserBundle\Model\User"?

500 Internal Server Error - ClassNotFoundException 

Stack Trace

1. in vendor\friendsofsymfony\user-bundle\Model\UserManager.php at line 40  
37.    public function createUser()
38.    {
39.        $class = $this->getClass();
40.        $user = new $class();
41.
42.        return $user;
43.    }

2. at UserManager ->createUser  () 

I've cleared the caches:

php app/console cache:clear --env=prod --no-warmup
php app/console cache:clear --env=dev --no-warmup

and made a composer update but nothings happened.

Versions:

  • FOS/user-bundle: v2.0.0

  • Symfony: v2.8.18

  • PHP: 7.1.2

  • Twig: v2.3.0

Here ist my user-class:

namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * web_user
 *
 * @ORM\Table(name="web_user")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\web_userRepository")
 */
class web_user extends BaseUser

{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
}

2 Answers 2

7

You forgot to change the user_class in your config.yml file.

Try user_class: AppBundle\Entity\User or similar.

Sign up to request clarification or add additional context in comments.

1 Comment

THX, you're right... I forgot to set the correct class name in the config.yml under fos_user / user_class
0

Symfony 4, create file: config/packages/fos_user.yaml

fos_user:
  db_driver: orm
  firewall_name: main
  user_class: App\Entity\User
  from_email:
      address: "[email protected]"
      sender_name: "Sender Name"

Info:

https://vfac.fr/blog/how-install-fosuserbundle-with-symfony-4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.