CakePHP4-身份验证-如何更改默认的userModel? [英] CakePHP4 - Authentication - How to change default userModel?

查看:62
本文介绍了CakePHP4-身份验证-如何更改默认的userModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照本教程设置身份验证 https://book.cakephp.org/authentication/2/en/index.html 与CakePHP4.

存储我的用户的表不称为用户".因此,当我尝试登录时会出现此错误:

 找不到基本表或视图:1146表'databasename.users' 

在哪里可以指定userModel?应该在哪个文件中设置?怎么样?

解决方案

您必须相应地配置相应的解析器,在这种情况下为ORM解析器.

解析器由标识符使用,标识符通过 resolver 选项接受解析器配置.因此,例如对于密码标识符,您可以这样做:

  $ service-> loadIdentifier('Authentication.Password',['resolver'=>['className'=>"Authentication.Orm",'userModel'=>'YourCustomModelName',],//....]); 

请注意,在传递解析器配置数组时,也必须传递类名,因为默认配置只是一个字符串(解析器类名),因此它不会与默认值合并,但会覆盖默认值!/p>

另请参见

I'm following this tutorial to set up Authentication https://book.cakephp.org/authentication/2/en/index.html with CakePHP4.

The table where my users are stored is not called "users" so when I try to log in it gives me this error:

Base table or view not found: 1146 Table 'databasename.users'

Where can I specify the userModel? In which file should it be set up? How?

解决方案

You have to configure the respective resolver accordingly, in this case the ORM resolver.

Resolvers are used by identifiers, which accept resolver configuration via the resolver option. So for example for the password identifier, you could do it like this:

$service->loadIdentifier('Authentication.Password', [
    'resolver' => [
        'className' => 'Authentication.Orm',
        'userModel' => 'YourCustomModelName',
    ],
    // ....
]);

Note that it's necessary to pass the class name too when passing an array of resolver configuration, as the default configuration is just a string (the resolver class name), so it will not merge with the defaults, but overwrite them!

See also

这篇关于CakePHP4-身份验证-如何更改默认的userModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆