yii2覆盖用户组件提供了以下错误:标识对象必须实现IdentityInterface

时间:2018-10-30 08:22:55

标签: php yii2 override yii2-advanced-app extend

common \ config \ main.php:

'components' => [
     'user' => [
               'class' => 'common\components\extended\User',
               'identityClass' => 'common\models\Users',
     ],
],
上述代码的

引用来自:https://www.yiiframework.com/doc/guide/2.0/en/security-authenticationhttps://github.com/dektrium/yii2-user/issues/6, 和 yii 2 : override user model

错误:

yii\base\InvalidValueException
The identity object must implement IdentityInterface.

设置:

yii2-advanced-app

php 7.0

component:common \ components \ extended \ User看起来像这样:

namespace common\components\extended;
...
class User extends Component
{

它与“ vendor \ yiisoft \ yii2 \ web \ User.php”文件相同,但具有新的命名空间和一些小的修改(“ can”函数及其他一些修改)

identityClass:common \ models \ Users看起来像这样:

namespace common\models;
...
class Users extends \yii\db\ActiveRecord implements IdentityInterface
{

从配置文件中删除“'identityClass'=>'common \ models \ Users'”行对错误消息没有影响

删除行“'class'=>'common \ components \ extended \ User'”,使代码直接运行到“ vendor \ yiisoft \ yii2 \ web \ User.php”中,由于非标准rbac而导致错误需要函数“ public function can($ permissionName,$ params = [],$ allowCaching = true)...”的设置被覆盖。

需求:使用“ common \ components \ extended \ User”覆盖“ vendor \ yiisoft \ yii2 \ web \ User.php”

任何帮助将不胜感激。

Ps。尝试过:关闭并重新打开,清除缓存...

0 个答案:

没有答案