我正在尝试集成FOSUserBundle
.SonataUserBundle
和捆绑包,HWIOauth
我已将.SonataUserBundle
FOSUserBundle
使用本指南作为基础,我设法设置了 OAuth 集成:在使用 facebook 帐户进行身份验证后成功创建了一个用户。
身份验证后,用户会自动重定向到我的索引页面,之后会立即抛出 DBALException
DEBUG - Read SecurityContext from the session
DEBUG - Reloading user from user provider.
WHERE
由于子句中的表引用无效:
An exception occurred while executing 'SELECT t1.username AS username2, [more t1 references] FROM fos_user t1 WHERE t0.id = ? LIMIT 1' with params {"1":1}:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.id' in 'where clause'
我了解t0
引用无效,因为它未包含在FROM
子句中,但不知道为什么引用它t0.id
而不是t1.id
(希望)相关代码
如果我理解正确,我的用户实体扩展了Sonata
用户实体,而后者又扩展了FOS
用户实体?
应用程序\奏鸣曲\用户捆绑\实体\用户.php
<?php
/**
* This file is part of the <name> project.
*
* (c) <yourname> <youremail>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
/**
* This file has been generated by the Sonata EasyExtends bundle ( http://sonata-project.org/bundles/easy-extends )
*
* References :
* working with object : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
*
* @author <yourname> <youremail>
*/
class User extends BaseUser
{
/**
* @var integer $id
*/
protected $id;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
}
站点\SiteBundle\Entity\User.php
<?php
namespace Sites\SiteBundle\Entity;
use Application\Sonata\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
private $facebook_id;
/** @ORM\Column(name="facebook_access_token", type="string", length=255, nullable=true) */
private $facebook_access_token;
/** @ORM\Column(name="google_id", type="string", length=255, nullable=true) */
private $google_id;
/** @ORM\Column(name="google_access_token", type="string", length=255, nullable=true) */
private $google_access_token;
public function __construct()
{
parent::__construct();
// your code here
}
config.yml的相关部分
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Sites\SiteBundle\Entity\User
sonata_user:
security_acl: false # was true
manager_type: orm
class:
user: Sites\SiteBundle\Entity\User