Facebook for Yii

I’m developing a website using Yii and I want the users to log in via Facebook Connect. I’ve got it working but the problem I found is that in /views/layouts/main.php, the $content is generated before main.php is run, so my Facebook Connect script is run after I’m done generating dynamic content.

I have a User model, and I need the user to log-in through Facebook before I can fetch data from my own database for that Facebook user. What I want to achieve is this scenario:

  1. User has already logged into Facebook previously and comes to my site.

  2. My javascript/cookie detects that the user has already logged into his Facebook account and spits out a UID.

  3. Using this UID, I use the User model to query for the UID and get the user data.

How can I do this? Sorry if my explanation of the problem is all over the place, but I’m just really confused… =(

here is how i did it…