我如何使用比&QUOT其他表;用户"对于CakePHP的AuthComponent? [英] How do I use a table other than "Users" for CakePHP's AuthComponent?

查看:125
本文介绍了我如何使用比&QUOT其他表;用户"对于CakePHP的AuthComponent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CakePHP的的 AuthComponent 的假设你有一个包含用户名和密码的用户表。我想找到一种方法,从覆盖到的用户帐户的默认表名。

CakePHP's AuthComponent assumes you have a Users table that contains a username and password. I'd like to find a way to override the default tablename from Users to Accounts.

背景资料:

Background Information:

我设计我的数据库的方法是有一个用户表和账表。

The way I have designed my database is to have a Users table and an Accounts table.

帐户


  • ID

  • id

USER_ID

用户名

密码

认证服务(例如,我的网站,Facebook,谷歌, OpenID的等)

authentication service (for example, my site, Facebook, Google, OpenID, etc.)

用户


  • 只是拥有用户的所有个人信息(年龄,性别等)

这样做的原因是,使得


  1. 每个用户可以有他们可以从这样登录多个账户,他们没有锁定到一个

  2. 我可以连接到一个账户的第三方服务更多迷死

现在回到问题....

Now back to the problem....

CakePHP有更改默认的字段名称的文件,但我不能改变默认的表名发现了什么,但相信它会在本质上是相似的...

CakePHP has documentation on changing the default field name, but I can't find anything on changing the default table name, but assume it would be similar in nature...

更改默认的字段名的例子:

Example of changing the default field name:

function beforeFilter() {
    $this->Auth->fields = array(
            'username' => 'username',
            'password' => 'secretword'
        );
 }

有没有办法做到这一点,或者我应该调整与CakePHP的惯例保持一致的表,仍然完成同样的事情?

推荐答案

在app_controller.php:

In app_controller.php:

function beforeFilter() {
    $this->Auth->userModel = 'Account';
}

这篇关于我如何使用比&QUOT其他表;用户"对于CakePHP的AuthComponent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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