User Session

hi everyone,

hope you are best of health. I am new in yii. i want to create a user session when user logged in he can acess only his data. like if admin login only admin can access their data and if another user is logged in he can access only their data. how can i do this. hopefully anyone help me.

thank you

Hmm, seems like this topic is not covered in the docs.

Ok, we have two functions:

public function get($key, $defaultValue = null)

public function set($key, $value)

So you can do something like this:


\Yii::$app->session->set('myVar', 'myValue');



and then


\Yii::$app->session->get('myVar');



or


\Yii::$app->session->get('myVar', 'defaultValue');

I think it’s more about access control. Check these:

https://github.com/yiisoft/yii2/blob/master/docs/guide/authentication.md

https://github.com/yiisoft/yii2/blob/master/docs/guide/authorization.md

Thanks for reply Orey but i am using yii 1.1 version how to do in this version of yii.

Why you’ve posted in 2.0 forum then? :) Topic moved.