FOSUser 已找到文件,但 class 不在其中,class 名称或命名空间可能有拼写错误

FOSUser The file was found but the class was not in it, the class name or namespace probably has a typo

我的实体是:

<?php

namespace MainBundle\Entity;

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

/**
 * @ORM\Table(name="lat_users")
 * @ORM\Entity
 */
class User extends lat_users
{
    // ...
}

和我的config.yml

...
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: MainBundle\Entity\lat_users
    from_email:
    
    ...

它说:

The autoloader expected class "MainBundle\Entity\lat_users" to be defined in file "/var/www/intranet/vendor/composer/../../src/MainBundle/Entity/lat_users.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

没看懂

您应该将 MainBundle\Entity\User 放在配置中,因为 lat_users 是 table 名称而不是实体名称。您的实体名称是 User,因此:

...
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: MainBundle\Entity\User
    from_email:

    ...

此外,作为最佳实践,始终使用 Singular CamelCase 作为 class 名称和 PHP 中的别名:

替换:

use FOS\UserBundle\Model\User as lat_users;

// ...

class User extends lat_users

来自

use FOS\UserBundle\Model\User as LatUser;

// ...

class User extends LatUser