views:

987

answers:

2

I am building a Facebook app using iframe rendering. I want to use CodeIgniter for the back end and am wondering what all the settings should be set to for CodeIgniter and Facebook to get along. Specific settings I am wondering about are:

  1. Facebook's canvas callback url (should it include the default controller and function)?
  2. config.php's base_url, index_page, uri_protocol, enable_query_strings
  3. Anything else I might be missing

How I have the Facebook interaction set up currently is creating a new controller FB_Controller that is added to the libraries folder that every one of my controllers inherit from. FB_Controller inherits from Controller and has a property $facebook that is instantiated using the API key and secret upon construction. Not sure if this the best approach.

I am also using mod_rewrite to get rid of index.php and just so there's no confusion here's the code:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
+1  A: 

I'm only use facebook connect in my application, to auto-login visitor that have connect their account with a facebook account.

I use facebook connect library in my application. This library is created by Elliot Haughin. Check it out, maybe it's can give you a start of creating your own library.

Donny Kurnia
+1  A: 

You shouldn't have to do anything special to get Facebook to work with your CodeIgniter application.

  1. The canvas callback URL is the landing page for your app. This is the page that Facebook presents to the user after she has accepted your app. This would normally be the root URL of your app (the page corresponding to the index action method of your default controller). But you could set it to any URL you please.
  2. Set base_url to the root URL of your web app eg. www.example.com/myapp/ (remember to include the trailing slash). Set index_page to the empty string if you plan on removing index.php from your URLs. Leave uri_protocol and enable_query_strings as default unless you have a good reason not to.
  3. Again, you shouldn't need to do anything special to make your CodeIgniter app compatible with Facebook.

Like you, I don't like having index.php in the URLs of my CodeIgniter apps so I remove them by enabling mod_rewrite for Apache and adding a .htaccess file to the root directory of my project with the following :

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Stephen Curran
Have you tried to do this? Links on the app does not work in Facebook unless the uri_protocol is path_info. But then the web app will not work (links in it).
jcmoney
I don't understand. Why will links not work in the Facebook app unless uri_protocol is set to path_info?
Stephen Curran
Not sure why I had to but I just ended up doing a conditional statement on the domain name to set it to either path_info or uri_protocol
jcmoney