Create new user in Yii2 Framework

by omer.razaMay 26, 2016
YiiFrame

This article helps to create a new user custom user in Yii2 basic template

Step 1: Create a new folder under project folder with name components.

 

Step 2 : Create a new test component under the components folder.

  • To create a new user in yii2 , we need to implent the functionality of built in user in vendor/yiisoft/yii2/User.php
  • Copy all the methods and its definition and paste it in test.php under components.
  • Change the following just in test.php
  • Change the name of the class from user to test
  • Create a new login url for test
  • Add a new cookie for test for logout purpose

Step 3: Now add the component in config/web.php beneath the default user array config.

'user' => [ 'identityClass' => 'app\modules\user\models\user,   
'enableAutoLogin' => true,   
'enableSession' => true,   
'loginUrl' => 'index.php',],   
'test' => ['identityClass' => 'app\modules\Test\models\Test,   
'class' => 'app\components\Seller',   
'enableAutoLogin' =>true,   
'enableSession' =>true,],

We have now created the new test user successfully.

search

Featured Articles

magneto security patch
January 2, 2026

Adobe Released a New Magento 2 Security Patch — What Store Owners Must Check Immediately

Read More
Automating Magento 2 Product Imports with BarcodeLookup API & Supplier Feed Extension
December 19, 2025

Automating Magento 2 Product Imports with BarcodeLookup API & Supplier Feed Extension

Read More
Magento 2 Product Import Guide: Integrating Foxway with Magento 2 Using AALOGICS Supplier Feed Extension
December 10, 2025

Magento 2 Product Import Guide: Integrating Foxway with Magento 2 Using AALOGICS Supplier Feed Extension

Read More
How Modaestile Launched a Fully Functional Mobile App in Record Time — Without Expensive Custom Development
December 5, 2025

How Modaestile Launched a Fully Functional Mobile App in Record Time — Without Expensive Custom Development

Read More
digital-marketing
November 26, 2025

What’s Changing in Digital Marketing Right Now — And How Smart Brands Are Adapting

Read More