Loading...

Admin


Published at : February 15, 2025


Read Time: 5 mints


Share the post :

facebookinstagramlinkedin

Create multiAuth in yii2 basic app manually

Create multiAuth in yii2 basic app manually
  1. Creating multiAuth in yii2 is a few clicks job if you are using RBAC in your app but if you want to get your hand dirty and do everything manually in your project, then cheers to you, you have came to the right spot. Follow the steps here and the outcome is a multiAuth all done by you.

Step1 :

create a basic app, using composer or download a skeleton of yii2 basic template.

Step2:

Create a module using gii and put the little code shown in gii in your config/web.php.

Step3:

Change your module.php . Add these lines in the init method.

public function init()
{
    parent::init();

    Yii::$app->set(\'user\', [
        \'class\' => \'yii\\web\\User\',
        \'identityClass\' => \'app\\modules\\admin\\models\\User\',
        \'enableAutoLogin\' => true,
        \'loginUrl\' => [\'admin/default/login\'],
    ]);

    Yii::$app->set(\'session\', [
        \'class\' => \'yii\\web\\Session\',
        \'name\' => \'_adminSessionId\',
    ]);
}

Here we are using user model in admin module to login to admin  login.

Do your itsy bitsy changes for your login mechanism

Write your own access control and you are done.and change your urlmanager as needed.

This should solve your issue.  If not you can send me your code snippet in the comments section.  If I get some time off from building something more awesome (or don’t get kidnapped by the aliens), I will surely revert back to you.

Happy coding to you then !!!

Existing Blogs

  • NestJS: Revolutionizing Backend Development with Elegance and Efficiency

    BY Admin | Jun 30, 2025

    NestJS: Revolutionizing Backend Development with Elegance and Efficiency


    Read more
  • Face Recognition using python

    BY Admin | Jun 30, 2025

    Face Recognition using python


    Read more
  • ReactJS Vs React Native: Which Is Your Best Fit in 2024

    BY Admin | Jun 30, 2025

    ReactJS Vs React Native: Which Is Your Best Fit in 2024


    Read more
  • Mean Stack Vs Full-Stack: Which Should You Choose?

    BY Admin | Jun 30, 2025

    Mean Stack Vs Full-Stack: Which Should You Choose?


    Read more
Loading...
Blog Detail - WIS