Symfony-FOS UserBundle错误。"试图从命名空间加载类'User'...... "通过打开/register页面[英] Symfony - FOS UserBundle Error: "Attempted to load class 'User' from namespace..." by opening the /register Page

本文是小编为大家收集整理的关于Symfony-FOS UserBundle错误。"试图从命名空间加载类'User'...... "通过打开/register页面的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想在Symfony中使用FOS UserBundle.

我已经将其配置为Symfony Doc的"开始使用FosuserBundle".

/登录页面正在工作,但是当我打开/注册页面时,我会收到错误:

尝试从名称空间" AppBundle \ Entity"加载类"用户". 您是否忘记了例如" Symfony \ Component \ Securent \ Core \ user \ user \ user"," Symfony \ Bridge \ Doctrine \ tests \ fixtures \ user"或" fos \ userbundle \ userBundle \ 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  () 

我已经清除了缓存:

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

并进行了作曲家的更新,但没有发生.

版本:

  • fos/user-bundle:v2.0.0

  • symfony:v2.8.18

  • php:7.1.2

  • twig:v2.3.0

在这里我的用户级:

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;
    }
}

推荐答案

您忘了更改config.yml文件中的user_class.

尝试user_class: AppBundle\Entity\User或类似.

其他推荐答案

Symfony 4,创建文件: 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"

信息:

-fosuserbundle-with-ymfony-4

本文地址:https://www.itbaoku.cn/post/2090805.html

问题描述

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;
    }
}

推荐答案

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

Try user_class: AppBundle\Entity\User or similar.

其他推荐答案

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