问题
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;
}
}
回答1:
You forgot to change the user_class in your config.yml file.
Try user_class: AppBundle\Entity\User
or similar.
回答2:
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: "mail@mail.com"
sender_name: "Sender Name"
Info:
https://vfac.fr/blog/how-install-fosuserbundle-with-symfony-4
来源:https://stackoverflow.com/questions/43206013/symfony-fos-userbundle-error-attempted-to-load-class-user-from-namespace