如何配置动态用户属性用户认证? [英] How to configure user authentication with dynamic user attributes?

查看:139
本文介绍了如何配置动态用户属性用户认证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来CakePHP的,我想从我的自定义的lib到CakePHP的迁移。

I'm new to CakePHP and i want to migrate from my custom lib to CakePHP.

我有,我的定制lib下,为用户属性是这样的:

I have, on my custom lib, for user attributes something like this:

auth_users 表就知道了user_ids

auth_users table to know the "user_ids":

CREATE TABLE IF NOT EXISTS `auth_users` (
  `id` int(11) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

auth_user_attributes 表来存储用户属性:

CREATE TABLE IF NOT EXISTS `auth_user_attributes` (
  `user_id` int(11) NOT NULL,
  `attribute` text NOT NULL,
  `value` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

所以每当我想通过USER_ID一个用户,我自定义的lib返回 $系统 - > auth->用户自>获取(1)

Array(
    'fullname' => 'José Moreira',
    'username' => 'Cuss',
    ...
)

如果我想保存用户,我有两种方法,保存整个阵列 $系统 - > auth->用户自>保存(USER_ID,user_attributes_array)或者通过属性 $系统 - > auth->用户自>把(USER_ID,user_attribute,user_attribute_value)

If i want to save user i have two methods, save an entire array $system->auth->user->save(user_id,user_attributes_array) or by attribute $system->auth->user->put(user_id, user_attribute, user_attribute_value)

我怎么能这样做介绍CakePHP?

How can i do something like this on CakePHP?

推荐答案

我会建议您重新设计架构,以适应CakePHP的约定。否则你将失去很多AUTOMAGIC的,我看没有意义的,你迁移到蛋糕,如果没有人强迫你。 用户不能有多个全名用户名。没有理由把全名用户名到另一个表。按照简单的身份验证和授权应用turorial ,你不会有任何疼痛。

I would suggest you to redesign your schema to fit CakePHP conventions. Otherwise you will loose a lot of automagic and I see no sense for you to migrate to Cake if nobody forces you. User cannot have more than one fullname or username. There is no reason to put fullname and username into another table. Follow Simple Authentication and Authorization Application turorial and you will have no pain.

然后就可以保存用户属性通过调用<一个href=\"http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-savemany-array-data-null-array-options-array\"相对=nofollow>用户 - > UserAttribute-> saveMany()

Then you can save user attributes by calling User->UserAttribute->saveMany().

这篇关于如何配置动态用户属性用户认证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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