Yii Framework Forum: Select Statement Using Username - Yii Framework Forum

Jump to content

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

Select Statement Using Username Rate Topic: -----

#1 User is offline   GaryHanks 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 27-January 13

Posted 27 January 2013 - 06:58 PM

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
0

#2 User is offline   Emily Dickinson 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 17-September 10
  • Location:Albuquerque, NM

Posted 27 January 2013 - 08:07 PM

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.yiiframew.../en/topics.auth

:mellow:
0

#3 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 228
  • Joined: 04-October 12

Posted 28 January 2013 - 01:29 AM

Hi , yes you can

1- read this article , talked about login with db
http://www.yiiframew...-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");

}


0

#4 User is offline   GaryHanks 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 27-January 13

Posted 28 January 2013 - 07:45 AM

Thank you i will try this!
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