Facebook Application Using CodeIgniter
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:
- Facebook's canvas callback url (should it include the default controller and function)?
- config.php's base_url, index_page, uri_protocol, enable_query_strings
- 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 s开发者_如何学运维ecret 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>
You shouldn't have to do anything special to get Facebook to work with your CodeIgniter application.
- 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.
- 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.
- 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]
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.
精彩评论