如何从CakePHP 2.0 FormAuthenticate对象获取$设置数据 [英] How to get $settings data out of CakePHP 2.0 FormAuthenticate object

查看:124
本文介绍了如何从CakePHP 2.0 FormAuthenticate对象获取$设置数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AuthComponent构建一个RememberMe组件,并且希望从XxxxAuthenticate对象中获取 BaseAuthenticate :: $ settings 数据(userModel和fields)数据,因此我可以知道我应该处理什么模型和字段,但我似乎不知道如何将数据退回。



任何建议? >

基本上我需要一些与 Auth :: getModel() Auth :: $ userModel



Cake-2.0.3

解决方案

Auth :: $ userModel仍然存在于2.0中。但是,您可能必须通过实例化对象而不是静态地访问它:

  $ modelData = $ this-& > userModel; 

如果未设置,则默认为User。



然后,您可以通过查看返回的第一个数组键来获取模型:

  $ modelName = key($ modelData [0]); 


I am building a RememberMe Component using the AuthComponent and would like to get the BaseAuthenticate::$settings data (userModel and fields) data out of the XxxxAuthenticate object so I can know what model and fields I should be dealing with, but I can't seem to figure out how to get that data back out.

Any suggestions?

Basically I need something with the same functionality as Auth::getModel( ) or Auth::$userModel from Cake 1.X.

Cake- 2.0.3

解决方案

Auth::$userModel still exists in 2.0. However, you probably have to access it via the instantied object rather than statically:

$modelData = $this->Auth->userModel;

If this isn't set, then it defaults to User.

You can then get the model by looking at the first array key that is returned:

$modelName = key($modelData[0]);

这篇关于如何从CakePHP 2.0 FormAuthenticate对象获取$设置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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