我正在使用Symfony 2.8,FosuserBundle 1.3和FosoauthserverBundle 1.5
对于那些捆绑包的所有课程,我最终以教义无法正确更新我的架构。我的意思是它没有考虑基础类别的字段。
CREATE TABLE oauh2_access_tokens (id INT NOT NULL, client_id INT NOT NULL, user_
id INT DEFAULT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_auth_codes (id INT NOT NULL, client_id INT NOT NULL, user_id
INT DEFAULT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_clients (id INT NOT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_refresh_tokens (id INT NOT NULL, client_id INT NOT NULL, use
r_id INT DEFAULT NULL, PRIMARY KEY(id));
这是我的配置:
doctrine:
orm:
#auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
COMPANYAuthBundle: ~
fos_user:
db_driver: orm
firewall_name: api
user_class: COMPANYAuthBundleEntityUser
#FOSOAuthBundle Configuration
fos_oauth_server:
db_driver: orm
client_class: COMPANYAuthBundleEntityClient
access_token_class: COMPANYAuthBundleEntityAccessToken
refresh_token_class: COMPANYAuthBundleEntityRefreshToken
auth_code_class: COMPANYAuthBundleEntityAuthCode
service:
user_provider: fos_user.user_manager
这是我的班级用户
<?php
namespace COMPANYAuthBundleEntity;
use DoctrineORMMapping as ORM;
use FOSUserBundleEntityUser as BaseUser;
/**
* Utilisateur
*
* @ORMTable(name="users")
* @ORMEntity
*/
class User extends BaseUser
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
}
所以,是的,我确实放置了正确的使用,而不是fos userBundle model user作为baseuser;
oauthserverbundle的类别相同的东西:(我只是把一个放在这里,它们都遵循相同的模式)
)<?php
namespace COMPANYAuthBundleEntity;
use DoctrineORMMapping as ORM;
use FOSOAuthServerBundleEntityClient as BaseClient;
/**
* Client
*
* @ORMTable(name="oauth2_clients")
* @ORMEntity(repositoryClass="COMPANYAuthBundleRepositoryClientRepository")
*/
class Client extends BaseClient
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
parent::__construct();
}
}
有人知道为什么不放入我的DB中的基类字段吗?谢谢:)
好吧,我在搜索10个小时后找到了解决方案...
解决方案是不要忘记添加fosuserbundle和fosoauthserververbundle,以及所有基类捆绑包到您的映射中.....
所以这应该是配置:
doctrine:
orm:
#auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
COMPANYAuthBundle: ~
FOSUserBundle: ~
FOSOAuthBundle: ~
另外,如果要使用每种路线,则不能从两个捆绑中继承一个捆绑包。因此,为每个创建一个捆绑包。然后在每个捆绑包中,添加以下功能:
public function getParent()
{
return "FOSOAuthServerBundle"; //Or return "FOSUserBundle"; but you can't put both
}