Yii Framework Forum: YII Auth multiple connection - Yii Framework Forum

Jump to content

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

YII Auth multiple connection How to dynamic change connection in auth component Rate Topic: -----

#1 User is offline   eotz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-February 15

Posted 02 May 2017 - 12:18 AM

i have multiple database and database have same table and all working fine. but how to change dynamic connection in auth modules. i had used session and state in config/main.php but dosent work.

//$a = Yii::app()->user->getState('fulldb') <<not working
//$a = Yii::app()->session['var'] = '2'; <<not working too
//$a = 2; // it work but i want dynamic and $a is based on user login

return array(
'components'=>array('authManager' => array(
            'class' => 'CDbAuthManager',
            'connectionID' => 'dbadvert'.$a, //<--how to change dynamic
            'behaviors' => array(
                'auth' => array(
                    'class' => 'auth.components.AuthBehavior',
                ),
            ),  
            'assignmentTable' => 'tbl_auth_assignment',
            'itemTable' => 'tbl_auth_item',
            'itemChildTable' => 'tbl_auth_item_child',
        ),


//multiple database connection works fine
        'db' => require(dirname(__FILE__).'/databaseUser.php'),
        'dbadvert' => require(dirname(__FILE__).'/database1.php'),
        'dbadvert2' => require(dirname(__FILE__).'/database2.php'),
}

0

#2 User is offline   reykel 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 21-June 15
  • Location:Camaguey, Cuba

Posted 23 May 2017 - 09:35 PM

On your current model (acording to your code) place this function
public function getDbConnection()
{
      return Yii::app()->dbadvert;
}

and keeping all the same way (including tableName function)run your app.

Good luck eotz
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