I am building a CakePHP app that requires admins, users, and merchants. Merchants will need to have a profile. Users will need to provide different info for their profile.
I currently have a user model handling login with ACL enabled.
That is all working fine.
What I cannot wrap my 开发者_C百科head around is how do I handle having a different profile for merchants and a different profile for users?
A typical website scenario would just be "user hasOne profile", but I need different profiles based on group type.
I can't seem to grasp how to have different data sets associated with users based on their group.
If your Users/Merchants/Admins all share the same User model, a polymorphic belongsTo
relationship to different Profile models should be the right thing to do. I.e. you make three different profile models like UserProfile, MerchantProfile and AdminProfile. In your User model, you have two fields: profile_class
and profile_foreign_key
and record data like profile_class: Merchant
, profile_foreign_key: 42
.
Also see this question.
Alternatively, you just associate the User model with all three profile models in a normal hasOne
relationship (where the foreign key goes into the Profile models), but that may make things more complicated.
精彩评论