简体   繁体   English

如何在Zend Framework中实现我的用户会话类

[英]How can I implement my user session class in Zend Framework

Hello I have a website that I have 3 classes AnonymousUser (for users who are not logged), Users (for common users registered) and UsersInSession (Users who has a session) all of these classes inherit from People class. 您好,我有一个网站,我有3个类AnonymousUser (对于未登录的Users ), Users (对于已注册的普通用户)和UsersInSession (具有会话的用户),所有这些类均从People类继承。

I get user data from a sql query and I serialize it who is logging and I save it to _SESSION["objectSession"] ,when the user is logged each PHP file I unserialize the _SESSION["objectSession"] to $objectSession object.. when I want to get my friendlist (in resources of MySQL) in objects I do: 我从sql查询中获取用户数据,然后将正在记录的用户序列化,然后将其保存到_SESSION["objectSession"] ,当用户记录每个PHP文件时,我_SESSION["objectSession"]序列_SESSION["objectSession"] $objectSession对象。当我想在对象中获取我的好友列表时(在MySQL资源中):

$myFriends=$objectSession->getFriends();

then I can print the data of my friends this way: 然后我可以用这种方式打印朋友的数据:

 <table> <tr> <td>Name</td><td>Lastnames</td> </tr> <?php
 while($objectFriend=$myFriends->fetchObject("Users")){ ?> <tr> <td><?
 echo $objectFriend->name; ?></td> <td><? echo
 $objectFriend->lastnames; ?></td> <?php } ?></tr></table>

Can I implement in Zend Framework with these classes? 我可以使用这些类在Zend Framework中实现吗?

I don't know if these classes can be Model or Controller.. 我不知道这些类可以是Model还是Controller。

For this question your version of ZF is irrelevant as it more of a structure question then anything else. 对于此问题,您的ZF版本无关紧要,因为它更像是结构问题,而不是其他任何问题。

For starters you currently have 3 classes that do largely the same thing. 对于初学者,您目前有3个类在很大程度上做相同的事情。 You can probably condense those 3 classes down to one user class that has 3 (or more) levels of authentication and access. 您可以将这3个类压缩为一个具有3个(或更多)身份验证和访问级别的用户类。

When using ZF2 you can your authentication (login) system using: Zend\\Authentication and then when your application decides which level of access each user gets you can use one of the access control components to control which resources the user can access. 使用ZF2时,可以使用以下方式进行身份验证(登录)系统: Zend \\ Authentication ,然后在应用程序确定每个用户获得的访问级别时,可以使用访问控制组件之一来控制用户可以访问哪些资源。
Zend/Permissions/Acl , traditional Object based ACL. Zend / Permissions / Acl ,传统的基于对象的ACL。
Zend/Permissions/Rbac , Role based ACL. Zend / Permissions / Rbac ,基于角色的ACL。

If you really don't want/need to role your own solution, you can find some really good access control and authentication solutions at ZF2 modules 如果您真的不想/不需要扮演自己的解决方案的角色,则可以在ZF2模块上找到一些非常好的访问控制和身份验证解决方案

[EDIT] [编辑]

Can I implement in Zend Framework with these classes? 我可以使用这些类在Zend Framework中实现吗?

Yes, although you may need to rename them for easier implementation. 是的,尽管您可能需要重命名它们以便于实施。

I don't know if these classes can be Model or Controller.. 我不知道这些类可以是Model还是Controller。

From your description it's likely your classes incorporate model, controller and probably even view elements in each class. 从您的描述来看,您的类可能包含模型,控制器,甚至可能在每个类中包含视图元素。 So some refactoring will likely be required. 因此,可能需要进行一些重构。

Typically these classes would be mostly model classes of the 'Domain Model' type that would interact with one or more controller to be processed and presented through the view. 通常,这些类主要是“域模型”类型的模型类,它们将与一个或多个要通过视图进行处理和呈现的控制器进行交互。

Thanks,Well maybe I did not ask the question very good..what I do with that 3 classes is check if the user have "privileges" to do it,for example: 谢谢,也许我不是很好地问过这个问题。我对这三个类的处理方式是检查用户是否具有“特权”,例如:

-Anonymous users (that inherits from People class) can't comment any profile. -匿名用户(继承自People类)无法评论任何个人资料。

-Users (inherits from People class too) can comment,and have its profile and pictures.Each user have a table of privacy,so dependends of the user if can comment their friends,or all users.This class have the checkprivacy($iduser) method that checks if the user can see the profile of $iduser. -用户(也可以从People类继承)可以评论,并拥有其个人资料和图片。每个用户都有一个隐私表,因此用户的依赖项可以评论其朋友或所有用户。此类具有checkprivacy($ iduser ),用于检查用户是否可以看到$ iduser的个人资料。 This class have the checkBlocked($iduserblock) function too,because it can check if the user is blocked and can't see the profile. 此类也具有checkBlocked($ iduserblock)函数,因为它可以检查用户是否被阻止并且看不到配置文件。

-People class (this class do the job) check if the session is an anonymous user,or a user (who is logged) if is logged we check if is blocked and we'll check if he can comment.If is an anonymouser is not necessary to check if he is blocked.. this class have the method loadProfile($id) to load a profile and more issues -People类(该类负责此工作)检查会话是否是匿名用户,或者是否记录了用户(已记录用户)是否被记录,我们检查是否被阻止,我们将检查他是否可以发表评论。不需要检查他是否被阻止..此类具有方法loadProfile($ id)来加载配置文件和更多问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM