I started working with Yii2 since few weeks and installed the advanced environment of Yii2 with front- and backend.
My destination is to realisize a frontend login with customers- and suppliers-users.
Because of this I created 2 tables called "customers" and "suppliers" with a different number ob columns. And a model for each table called "customer" and "supplier".
After a long time of research I generated the two classes "CustomerIdentity" and "SupplierIdentity" with extends to yii/web/User. Then I write in the config.php this lines (instead of the common User-Component):
Thanks for the fast support, but the given topic doesnt describe my situation. I use only frontend (at first) with two types of users and I dont use the session component (in the config.php).
I don’t think it’s possible to use multiple user identity classes in an application.
You’d better create a single “User” model (and the underlying “user” table) that holds all the necessary attributes for both Customer and Supplier, with an attribute (a column) that specifies the user type. If you don’t want to have many redundant columns, then you may consider separating those user type specific columns to other related tables (“customer” and “supplier”).
Yes of course - you are right. In my last project, I have one table for both, but this new project-"upgrade" I want programming more professionell und more flexible for the future.
Is it so complex to realize that? I thought Yii has all equipments for all situations without much expense.
PS: Sorry, that I dont answer yesterday, but this forum dont allow me to write a third post.
No problem. There are some restriction on the new comers in order to prevent possible spamming.
The point here is that we need to have a single ‘user’ application component (yii\web\User) that has a single ‘UserIdentity’ class. This is the schema with which Yii 2 handles the user authentication. All the users of your application must have an unique ID, no matter what type of user they might be. Multiple ‘user’ components or ‘UserIdentity’ classes are not in the basic assumption.
Yes, I think you definitely need to learn how to use RBAC.
I’m using “yii2-admin” in my projects, too. I can recommend this extension. It’s a simple and straightforward web UI for managing yii2 RBAC hierarchy. I like its simpleness. Also the idea of access control filter using “route permissions” is very convenient.
But, well, I don’t use “yii2-admin” to create/update RBAC hierarchy. I just use it to check and see how my RBAC hierarchy is constructed, and to assign roles to the users. I create/update roles and permissions through “migrations” because I want to have the source code of my RBAC hierarchy.
In your case, you may consider creating default roles of "customer" and "supplier" based on the user type. Or you may also introduce some administrative roles to manage the system.