How to change the default USER table to use another one

Hi people,

I have in my db a table named USERS, and after installing yii2 and doing the migration it creates a new table named USER for loigin/lougout etc…

Im a bit lost I don’t know exactly which field I’ve to modify in LoginForm.php/SiteController.php/Login.php etc…

How can I modify it in order to use my USERS table rather than the one created by yii migration ?

Thank you

It depends what you want to do. For example if you want to create additional functionalities you have 2 options: add new code to User.php, or create new model and name is somehow else, and use that model in your code. If you do not like code from the User model then create the new one rewrite all functionalities, but in that case you are doing unecessary double work in my opinion.

I already have a table named USERS which has all rthe necessary columns abd it’s related to the others tables in the db (foreign key etc)

I’ve created the model and controllers for both tables (may table USERS and the default one created by yii USER) but is sims that by defautlt in SiteController.php LoginForm.php Login.php… it uses the one that the framework created USER (and it has no relation with the others table in the db)

But I want to use ny own table USERS

ps : this db is from my previous project that I want to upgrade and not created from scratch

Well just update code in those files from using User to user Users.

instead of:


use common\models\User

use:


use common\models\Users

if your Users model is located there…

And if you are in the common namespace ( like LoginForm.php ), you will have to dive in code and change User static calls to Users. You will have to update everything…

Thanks you for your help

1- in my files I have something like


use common\models

the


\User

doesn’t exist

2- I don’t exactly what I need to modify :unsure:





edit common/models/User.php


class User extends ActiveRecord implements IdentityInterface

{

...

    public static function tableName()

    {

        return '{{%users}}'; // <- try modifying this line with your table name

    }

...

}



thank you for your help