Select Statement Using Username

Hi, sorry if this post is in the wrong place or anything im new.

i was just wondering is it possible to do a select statement where it only shows data for the user that is logged in?

i havent created anything yet, i was just wondering if this is possible.

i am looking to create a timetable sort of application where a user logs on and all of their classes are shown and only there classes are shown, but also i would like to allow the admin to log and amend any of the dates or times of the classes.

Thanks in advance

Gary

Easy to do. Build your user table however you please. Let user authenticate. As part of authentication, set

$this->_id to the userid in your user table.

ost authentication, you can get the user variable with :

$user = Yii::app()->user;

You can then create all the SELECT statements you wish.

See excellent tutorial for details:

http://www.yiiframework.com/doc/guide/1.1/en/topics.auth

:mellow:

Hi , yes you can

1- read this article , talked about login with db

http://www.yiiframework.com/forum/index.php/topic/20832-solveduser-login-with-db/

2- when user logged in you need to register user id or username if user name is unique by add it to session or cookie

add as session :

$this->setState(‘id’, $record[‘id’]);

or

$this->setState(‘username’, $record[‘username’]);

then you can call id or username from any controller in your app like




//// get all articles related to loggedin user  


if( isset(yii::app()->user->id)){/// if logged in  and had id 




$id=yii::app()->user->id;

$model=articles::model()->findall("writer_id=$id");


}

Thank you i will try this!