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

woocommerce_main_img
October 10, 2025

The Hidden Power of AI for WooCommerce: 3 Tools You’re Missing

Read More
Should you upgrade to laravel 12?
October 3, 2025

Should You Upgrade to Laravel 12? Features, Risks & Upgrade Checklist

Read More
Odoo 19 AI At A Glance
September 26, 2025

Odoo 19 AI Features — From Automation to Autonomous Decisions: The Next Generation ERP Blueprint

Read More
vibe coding mobile app
September 18, 2025

Vibe Coding in Mobile App Development: From Prompts to Prototypes

Read More
rafraf-img
September 11, 2025

Case Study: RafRaf – Powering Saudi Arabia’s Auto Parts eCommerce with Headless Commerce

Read More