Yii Framework Forum: calling fields from other table using key - Yii Framework Forum

Jump to content

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

calling fields from other table using key Rate Topic: -----

#1 User is offline   Joans 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 26-November 14

Posted 27 November 2014 - 06:46 AM

Can anyone helps me to clear this..

i need to display the username from `user` table in `question` view file.. using userId which is the key column for two tables..

My table structure is this..

table name `user`
columns=> userId,userName, userType
key=> userId(primary)

table name `question`
columns=> userId(foreign key references `users`), questionId(A_I),question
key=>questionId

when user posts new question his userId will be stored in `question` table..

Now i need to display the username in question view file..

Since i am new to Yii i am not able to do this i don't know anything about this.. So pls help me..
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 27 November 2014 - 10:29 AM

You need to learn about configuring and using relations. If you used yiic or Gii to generate your models and your foreign key constraints were correctly set up, the relations may already exist in the model classes.
0

#3 User is offline   dragan.zivkovic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 13-September 12

Posted 27 November 2014 - 01:11 PM

All U need to do is to setup relation:

http://www.yiiframew...elational-query
2

#4 User is offline   jecartas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 28-November 14

Posted 28 November 2014 - 03:34 AM

This very usefully for :) Thank you
0

#5 User is offline   Joans 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 26-November 14

Posted 28 November 2014 - 07:58 AM

Thank you friends.. It helps me to learn Yii with interest..
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