在Zend_Auth的,我可以得到一个域模型用户对象,而不是stdClass的? [英] In Zend_Auth, can I get a domain-model User object instead of stdClass?

查看:685
本文介绍了在Zend_Auth的,我可以得到一个域模型用户对象,而不是stdClass的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然工作在一个应用程序的登录部分,我发现自己遇到了一个问题:

我的模型是基于活动记录,通过扩展一个Zend_Db_Table_Row对象。每当我必须处理一个用户,我想通过用户对象(即扩展的表行)来做到这一点。然而之外,Zend_Auth_Adapter_DbTable :: getResultRowObject()返回一个stdClass的,我无法找到一个方法来告诉者Zend_Auth_Adapter_DbTable使用特定Db_Table。

我是我到目前为止已经发现三个选项:

  1. 编写自定义Zend_Auth_Adapter,返回相应的类对象(使用Zend_Db_Table的内部)。

  2. 在认证执行stdClass已经和一些写作的用户对象的一些阅读 - 你可以创建一个Zend_Db_Table_Row类,而无需实际使用Zend_Db_Table的创建它

  3. 请远离活动记录到完整的领域驱动的开发,从用户对象分开我的数据的访问了。然后写一个第二映射器,以填补stdClass的,而不是表行的用户对象。

我的两个问题:哪这些,你会建议?而且是有什么我失踪?

我讨厌做这些,然后发现我失去了一些东西明显的框架。有谁知道,如果有一个'适当'的方式来这样做?

问候, 桑德

解决方案

有没有正确的方式做你想要什么。该方法你应该展示的所有工作。

我个人赞成存储只是一个ID为Zend_Auth的用户 - 如果你要保存所有用户的详细资料完整的对象,它会出现不一致的现象,如果用户是要改变自己的信息

在一个项目中,我曾经写了提供用户到控制器控制器插件。它基本上采取了ID从Zend_Auth的建立和在此基础上用​​户对象。这也创造了的情况下,没有ID匿名用户对象。不是说这是最好的方法,但它的透明和合作。

While working on the login part of an application, I find myself running into an issue:

My model is based on Active Record, by extending Zend_Db_Table_Row objects. Whenever I have to deal with a user, I'd want to do this through the User object (being an extended table row). However, Zend_Auth_Adapter_DbTable::getResultRowObject() returns a stdClass and I can not find a way to tell Zend_Auth_Adapter_DbTable to use a specific Db_Table.

My three options that I've found so far:

  1. Write a custom Zend_Auth_Adapter, to return the proper class object (using Zend_Db_Table internally).

  2. After authentication perform some reading of the stdClass and some writing of the User object - can you create a Zend_Db_Table_Row class without actually using the Zend_Db_Table to create it?

  3. Move away from Active Record into complete Domain Driven development, separating my data access away from the user object. Then write a second mapper to fill the User object with stdClass instead of the table row.

My two questions: Which of these would you recommend? And is there something I am missing?

I'd hate to do any of these and then find out I'm missing something obvious in the Framework. Does anyone know if there is a 'proper' way to be doing this?

Regards, Sander

解决方案

There is no "proper" way to do what you want. The approaches you show should all work.

Personally I'm in favor of storing just an ID for the user in Zend_Auth - if you were to store a full object with all user details, it would fall out of sync if the user was to change their info.

In a project I once wrote a controller plugin which provided the user to the controllers. It basically took the ID from Zend_Auth and built a user object based on it. It also created an anonymous user object in case there was no ID. Not saying this is the best approach, but it's transparent and worked.

这篇关于在Zend_Auth的,我可以得到一个域模型用户对象,而不是stdClass的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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