FOSUserBundle or PUGXMultiUserBundle to have two different user profiles (Symfony2)

隐身守侯 提交于 2019-12-08 23:32:41

问题


I'm doubtful about how to approach this problem:

My Symfony2 app for this issue has two different profiles, name 'em "Seller" and "Buyer". The goal is to keep a bunch of attributes about a "Seller", and, on the other hand, not much about the "Buyer" (email and password would do it).

I realise that it's not easy to have two different entities log in and register using FOSUserBundle. There are quite some other bundles, such as PUGXMultiUserBundle that 'hack' FOSUserBundle, and are not easy to config/implement.

So my quiestion is: Is it more correct to use the hack PUGXMultiUserBundle proposes, dealing with its implementation and config, or is it better to stick to FOSUserBundle, have a User entity, and a one-to-one relation with a "Seller" entity that represents the attributes of a Seller different from a buyer? There would be another problem with that approach, with the registration form, that should be splitted in two, for Seller and Buyer register (which I don't know if it is possible/advisable using FOSUserBundle)

I hope you guys help me get it right. Cheers :)


回答1:


I would definitely use the PUGXMultiUserBundle for that. I don't think it's a hack, it just implements a discrimination table that will be like:

1User Table

----------------------------------------
| id  | username  |  type  |------------
|-----|-----------|--------|------------
|  1  |  mgdepoo  | buyer  |------------
|  2  | Sydney_o9 | seller |------------
----------------------------------------

2Buyer Table

----------------------------------------
| id  |  buyer_specific_field_1
|-----|---------------------------------
|  1  |  
----------------------------------------

3Seller Table

----------------------------------------
| id  |  seller_specific_field_1
|-----|---------------------------------
|  2  |  
----------------------------------------

That's all there is really.

I think that's exactly what you need especially if you wish to have different profiles for your users. You will have 2 registration forms as well (but you can make one with a choice box buyer/seller if you want to).

I personally use this bundle and it works great for me. Now, one of the question you might want to ask yourself is what if a buyer wants to be a seller as well. Does he want to have another email address? That is a choice that you'll have to make.



来源:https://stackoverflow.com/questions/21043055/fosuserbundle-or-pugxmultiuserbundle-to-have-two-different-user-profiles-symfon

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