Php FOSOauthServerBundle\uuuu构造函数错误
我在symfony2中使用restfulapi已经有一段时间了。直到昨晚我创建了新的实体类之前,一切似乎都正常。尝试请求访问令牌时出错。我收到以下错误消息:Php FOSOauthServerBundle\uuuu构造函数错误,php,symfony,symfony-2.7,fosoauthserverbundle,Php,Symfony,Symfony 2.7,Fosoauthserverbundle,我在symfony2中使用restfulapi已经有一段时间了。直到昨晚我创建了新的实体类之前,一切似乎都正常。尝试请求访问令牌时出错。我收到以下错误消息: Catchable Fatal Error: Argument 2 passed to FOS\OAuthServerBundle\Event\OAuthEvent::__construct() must be an instance of FOS\OAuthServerBundle\Model\ClientInterface, insta
Catchable Fatal Error: Argument 2 passed to
FOS\OAuthServerBundle\Event\OAuthEvent::__construct() must be an
instance of FOS\OAuthServerBundle\Model\ClientInterface, instance of
TeamGraduate\APIBundle\Entity\Client given, called in /Volumes/SK Repo
1.0/Projects/Stalin Kay/Web Development/htdocs/TeamGraduate/tg-api/vendor/friendsofsymfony/oauth-server-bundle/FOS/OAuthServerBundle/Controller/AuthorizeController.php
on line 57 and defined 500 Internal Server Error -
ContextErrorException
请帮忙。我的s2项目使用FOSOauthServerBundle,如文档中所述。如果我在客户端重写构造函数,它会抛出一个致命错误:无法调用构造函数
编辑:
注:我要澄清的是,在我根据更新后的数据库生成新实体之前,一切都很正常。我还使用composer update更新了项目的依赖项
AccessToken.php
<?php
// src/Acme/DemoBundle/Entity/AccessToken.php
namespace TeamGraduate\APIBundle\Entity;
use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class AccessToken extends BaseAccessToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
<?php
// src/Acme/DemoBundle/Entity/AuthCode.php
namespace TeamGraduate\APIBundle\Entity;
use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class AuthCode extends BaseAuthCode
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
<?php
// src/Acme/DemoBundle/Entity/Client.php
namespace TeamGraduate\APIBundle\Entity;
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Client extends BaseClient
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
}
<?php
// src/Acme/DemoBundle/Entity/RefreshToken.php
namespace TeamGraduate\APIBundle\Entity;
use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class RefreshToken extends BaseRefreshToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
我相信我已经找到了解决办法
使用下面的命令创建一个FOS目录,并在src下创建
php app/console doctrine:mapping:import --force TeamGraduateAPIBundle xml
解决方案:
删除目录,一切都应该正常。您的客户机
实体是否实现客户界面
?你也可以发布吗?@chapay,我没有实现ClientInterface。我使用的是extend FOS\OAuthServerBundle\Model\Client not Entity中指定的方式\Client@udan,虽然出现了另一个问题,但我会尽力解决。谢谢你们。@udan,当我使用FOS\OAuthServerBundle\Model\*并发布php应用程序/控制台条令:schema:update——force时,这将删除FOSOauthServerBundle在我的数据库中添加的所有列。我在尝试授权客户端时得到无法识别的字段:randomId。