How to constitute discrete logins for Admin and Employee in yii2?

I am using yii2 basic application. I have code using simple Model, Controller and Views.

I have Employee CRUD application in yii2. I have configured the user application component for authentication purpose and is working properly where only authenticated users can login.

Now I want that when Admin logs in, he should see the admin panel which consist of Dashboard, Employee, Employee Training and other menus. Now when Admin clicks on Dashboard menu, he should see some statistics. Similarly when clicked on Employee menu, he should be able to access Employee CRUD and when clicked on Employee Training, Employee Training CRUD application should be accessed.

Admin creates the Employees and Employee Training for employees. Admin should create roles and assign roles to Employees. Once an employee is created and role is assigned, then Employee should be able to log in into his account.

When Employee logs in, he should be able to see employee control panel which consists of Dashboard, My Profile and some other menus. When employee clicks on My Profile menu, he should be able to view only his profile. Similarly when there is some CRUD application such as SHGGroup creation where employee creates group. Here if Employee A creates 4 groups and Employee B creates 10 groups, then when employee A logs in to his account he should be able to access only his created 4 groups. Similarly when Employee B logs in, he should be able to access his created 10 groups and so on.

Should I need to design the application using modules, or using simple model, controller and views is fine?

  1. How can we have login for such case?

  2. Is only one login window sufficient?

  3. Do we need to create two separate login window for Employee and Admin? If so how to implement that? Do we need to create

    one more user application component?

If we create a separate login window where from first login window employees can log in into the application and from second log in window, Admin can enter username and password and, then he can access everything in the application.

What would be the way to implement?

You can just use one Model.

It is presumed that you have already setup a way of knowing the EmployeeX is admin and EmployeeY isn’t. For the Admin menu, use the visible attribute of the menu item

['label' => 'Home', 'url' => ['/site/index'], 'visible'=>'your-admin-check-here'],

Look at the default layout to see how yii selects between isGuest and not.

To make sure anyone how goes to admin page needs to be/logon, make all actions in the AdminController require being an Admin. In the advanced template the backend (read admin) web app uses

            'access' => [

                'class' => AccessControl::className(),

                'rules' => [


                        'actions' => ['login', 'error'],

                        'allow' => true,



                        'actions' => ['logout', 'index'],

                        'allow' => true,

                        'roles' => ['@'],





in the behavior section of the SiteController. The ‘@’ in the second roles is for logged on users. This can be modifies the do you isAdmin check. I believe is you take the ‘actions’=> line out it means all actions.