简体   繁体   中英

Symfony FOSUserBundle Cannot instantiate abstract class FOS\UserBundle\Model\User

I have a fresh isntalation of Symfony 2.4 + FOSUserBundle. I just configured FOSUserBundle, this guide: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md

Now I try to create a new user with the CLI

fos:user:create --super-admin user user@domain.com password1

And I get this error

PHP Fatal error:  Cannot instantiate abstract class FOS\UserBundle\Model\User in /var/www/symfony2/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Model/UserManager.php on line 55

config.ylm

...
fos_user:
    db_driver: propel
    firewall_name: main
    user_class: FOS\UserBundle\Model\User
...

When access /register I get the same error, but /login seems to work fine (although I cant login, since I have no users)

Any ideas? Thanks in advance

EDITS:

new user class:

namespace g9\BoBundle\Model;

use FOS\UserBundle\Model\User as MyUser;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManager;

class User extends MyUser {
    # .. no code here yet
}

When I use CLI to create user I get:

  [InvalidArgumentException]
  This user instance is not supported by the Propel UserManager implementation

Should I submit another question? (The initial question got an answer

You can't use provided User model, you have to extend it and create your own .

When you do that, set user_class configuration parameter to namespace of your User model (which extends FOSUser's one).

At the moment, your user_class is set to their abstract User and therefore it breaks.

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