Yii Framework Forum: Centralized user database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Centralized user database Rate Topic: -----

#1 User is offline   saranvarma 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 09-July 17

Posted 22 December 2017 - 03:38 AM

HI,

I have multiple yii2 applications . I want to use common user table for all my yii2 applications. Iam using dektrium yii2-user extension in all my applications . Can you please suggest me some work around for this ?
0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,546
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 22 December 2017 - 05:36 AM

add another database component to your yii app configure it to connect to user database and tell active record to use that connection

'components' => [
        'userDb' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=testdb',
            'username' => 'demo',
            'password' => 'demo',
        ],
    ],


class User extends ActiveRecord
{
    // ...

    public static function getDb()
    {
        // use the "db2" application component
        return \Yii::$app->userDb;  
    }
}

1

#3 User is offline   saranvarma 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 09-July 17

Posted 22 December 2017 - 05:53 AM

Thank you alrazi :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users