Kohana 3.3 expanding the Auth module

戏子无情 提交于 2019-12-23 01:04:58

问题


I'm building an application using the Auth module for which I need at least 3 account types : Employer, Employee and Client. Since these accounts have different properties, functions and relationships (ex: employers has_many employees) I guess I need to have them on 3 separate ORM models.

The method I thought was to tweak the Auth module to replace the 'User' model with the appropriate sub-model (employer, employee, client), corresponding the the user type in the database.

Can this be done, or is it bad practice?


回答1:


For such rurposes you need to create different Model classes for each account type extending default Auth_ORM's Model_User class.

Then you need to create new Auth_ORM class extending Kohana_Auth_ORM class in your application/classes folder.

In this file you need to rewrite protected _login() method, so its $user variable to point to required account type.




回答2:


I have found interesting repository here: https://github.com/alexgisby/MAuth. I have the same problem as You have, so maybe if You manage to resolve it You could share the solution. I think the repository from this link could be a solution, but i didn't manage to implement it so far




回答3:


You can have 1 model - User and 3 different roles. And depending to role, you can load specific module, which will contain required classes.

For example, if User has role Employee you will load modules/role_employee



来源:https://stackoverflow.com/questions/15714047/kohana-3-3-expanding-the-auth-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!