Jump to content
Larry Ullman's Book Forums

Models + Table Joins With Yii

Recommended Posts

When a user signs up to my website the information taken from the registration page needs to be put into 3 separate tables, a users table, user_status table and a user address table, how can such a situation be done using yii, when you can generate only one controller per model? I am also rerunning over the SQL stuff and would like to practice doing TABLE JOINS, how can such be done using Yii?

Link to post
Share on other sites

Table joins are very easy in Yii by the look of it. A simple google search for 'yii query' gave me this link:




You would do something like this:

$user = Yii::app()->db->createCommand()
   ->select('id, username, profile')
   ->from('tbl_user u')
   ->join('tbl_profile p', 'u.id = p.user_id')
   ->join('tbl_another o', 'u.another_id = o.another_id')
   ->join('tbl_mother m', 'u.mother_id = m.mother_id')   
   ->where('id=:id', array(':id'=>$id))


Never used Yii, but a simple google search can solve most of your problems.

  • Upvote 1
Link to post
Share on other sites

Yes it was Google i did first run a search in, but intially searched for "Yii Table Joins" nothing came up with nothing that was helpful. I see your search on Yii query brought up some better results, yes i guess it is a query. I also checked my books but didn't find anything much in there, so that's why i was asking here for a pointer. Thanks for your help AC.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...