简体   繁体   中英

Symfony 4 FosUserBundle - error on /register route - cannot find User entity

Installing FOSUserBundle I got the following error when trying to access /register:

Class 'AppBundle\\Entity\\User' not found

Well, here is the User entity, which is under /src/Entity/User.php:

namespace AppBundle\Entity;

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

/**
 * @ORM\Entity
 * @ORM\Table(name="`user`")
 */
class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

public function __construct()
{
    parent::__construct();
}
}

Otherwise, FOS was able to generate the user table on the db and also all the routes were created.

Also FOS's /login route works fine insofar as it shows the login form.

FOS's configuration is under /config/packages/fos_user.yaml and looks like this:

fos_user:
    db_driver: orm 
    firewall_name: main
    user_class: AppBundle\Entity\User
    from_email:
        address: "my.email@example.com"
        sender_name: "myname"

Any ideas? Thanks

Your namespace specify an AppBundle but you say that your file is in /src/Entity/User.php .

Put it in /src/AppBundle/Entity/User.php and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM