两个表与 sfDoctrineGuard 用户表(symfony)的关系
嘿,
我已经在我的网络应用程序中启动了一个部分,用户需要经过身份验证才能使用它。我有两个相关的表:客户和企业......第一个是想要购买产品的用户,第二个是想要销售产品的“用户”。
有什么更好的方法来做到这一点?与 user_table 的关系是 1:1?我如何区分哪一种用户类型?因为用户类型只能编辑一些信息,而企业可以访问其他模块...
非常感谢。
Hy,
I have started in my web application a part who users needs to be autenticated to work with it. I have two tables related: Customer and Enterprise.... the first one are users who want to buy a product and the second one are "users" who want to sell products.
What is better way to do that? Relation 1:1 with user_table? how can i differentiate wich one user type is? Because user types only can edit some information and enterprise have acces to another modules...
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
hasReference()
函数模型。例如,您的模型
Customer
与User
具有如下关系:然后您可以测试用户是否属于 customer 类型(在控制器中):
为了使这更容易,您可以添加将此方法添加到您的
myUser
类中:当然对于 Enterprise 来说也是如此。
即使使用两个不同的表,您也可以使用
hasCredential()
方法,如果您只想检查权限,这是最简单的方法。如果您想访问企业和客户用户的某些属性,您也可以结合使用这两种方法。
更新:
好吧,假设客户和企业用户具有不同的权限,我会采用用户组方法。这更适合 sfGuard 的组模型。如果您随后知道某个用户位于
Customer
组中,则您就知道该用户拥有对客户对象的引用。但这当然意味着您必须将正确的组分配给新用户才能正常工作。
You could use the
hasReference()
function on the model.E.g. your model
Customer
has a relation toUser
like this:Then you can test whether the user is of type customer (in the controller):
To make this easier you can add this method to your
myUser
class:Same of course for Enterprise.
Even using two different tables, you can make use of the
hasCredential()
method, and this is the easiest way if you only want to check for permission.If you want to access certain attributes of the enterprise and customer user you can also combine both approaches.
Update:
Well, assuming that Customers and Enterprise users have different permissions, I would go with the user group approach. This fits better to the group model of sfGuard. If you then know that a user is in group
Customer
, you know that the user has a reference to a customer object.But this means of course that you have to assign the the right group to a new user in order to work correctly.
您的桌子真的需要分开吗?如果没有,您可以为这两种类型的用户使用 sfGuard 插件提供的标准 sf_guard_user 表,然后使用组功能将用户分配到“客户”组或“企业”组。
检查用户所属的组将允许您显示(或隐藏)该用户类型的适当内容。在您的操作中类似这样:
或在您的视图/模板中使用
$sf_user
变量。Do your tables really need to be separate? If not, you could use the standard sf_guard_user table provided with the sfGuard plugin for both types of user, and then use the groups functionality to assign the user to either the "Customer" group or the "Enterprise" group.
Checking the group that the user belonged to would allow you to display (or hide) the appropriate content for that user type. Something like this in your action:
or using the
$sf_user
variable in your view/templates.