fwalter
(Walter)
June 9, 2010, 5:30pm
1
Hi,
i am trying to have two different user-objects in our application.
So i extended CWebApplication and added the CWebUser object Yii::app()->backendUser.
The problem is now, that if i use the login for backendUser, the ‘old’ Yii::app()->user object is also logged in, and vice versa.
Is there a way to do this, or can there only be one object of CWebUser in an application?
Thanks in advance,
Florian
Y11
(Y!!)
June 9, 2010, 6:57pm
2
I assume you want to have a different user object in the backend module?
Open BackendModule.php and add this to the init() method:
Yii::app()->setComponent('user', Yii::app()->backendUser);
and in your config define the backend user (you don’t need to extend CWebApplication):
'components'=> array(
...
'backendUser' => array(
'class' => 'CWebUser',
),
...
),
Now in the backend module you can simply use Yii::app()->user which refers to the configured backendUser.
fwalter
(Walter)
June 10, 2010, 8:08am
3
Thanks for your answer.
The problem is, that i need to know in the frontend, if the user is logged-in in the backend. Moreover he can also be logged-in in the frontend, at the same time.
That’s why i try to use two objects of CWebUser. But they seem to interfere each other…
fwalter
(Walter)
June 15, 2010, 1:54pm
4
I found a solution which seems to work for us here.
We use a different stateKeyPrefix for the second user instance.
'components'=> array(
...
'backendUser' => array(
'class' => 'CWebUser',
'stateKeyPrefix'=>'backend',
),
...
),
With this set, the two instances don’t interfere anymore.
mikl
(Mike)
June 16, 2010, 7:36am
5
@florianwalter :
Nice approach. Please let us know, in case you find any issues with this solution.
KieranA
(Hiddentiger)
October 10, 2011, 1:55pm
6
I tried the solution from @florianwalter but if you logout of one it will log you out of the other.
Is these another way around this?
Am a newbie
In my application i want to implement two login instances
1.Jobseeker
2.Recruiters
So far i have being able to do it but the Yii::app()->user->isGuest and Yii::app()->jobseeker->isGuest
still refer to each other. This is my configuration.
‘components’=>array(
'user'=>array(
// enable cookie-based authentication
//'allowAutoLogin'=>true,
'loginUrl'=>array('companydetails/accessdenied'),
'returnUrl'=>array('companydetails/comarea'),
'stateKeyPrefix'=>'_com'
),
'jobseeker'=>array(
// enable cookie-based authentication
//'allowAutoLogin'=>true,
'class'=>'CWebUser',
'loginUrl'=>array('jobseeker/j_logins'),
'stateKeyPrefix'=>'_js',
// 'returnUrl'=>array('jobseeker/jsarea'),
),
i notice something. If i add ‘stateKeyPrefix’=>’_js’,or ‘stateKeyPrefix’=>’_com’ it will b redirecting me to ‘loginUrl’=>array(‘companydetails/accessdenied’),
Please help!!!
[/quote]