2

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?

4

3 回答 3

0

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.

在这个文件中你需要重写protected _login()方法,所以它的$user变量指向所需的帐户类型。

于 2013-04-01T14:12:17.997 回答
0

我在这里找到了有趣的存储库:https ://github.com/alexgisby/MAuth 。我和你有同样的问题,所以如果你设法解决它,你可以分享解决方案。我认为此链接中的存储库可能是一个解决方案,但到目前为止我还没有设法实现它

于 2013-04-08T09:06:26.213 回答
0

您可以拥有 1 个模型 - 用户和 3 个不同的角色。并且根据角色,您可以加载特定的模块,其中将包含所需的类。

例如,如果用户具有角色 Employee,您将加载 modules/role_employee

于 2013-04-08T22:31:49.363 回答