Best way to implement Facebook PHP SDK into Yii Framework
Ya. download Facebook SDK files and Keep it in protected/components/Facebook then edit your config/main.php with
'import'=>array( //autoloading model and component classes 'application.models.*', 'application.components.*', 'application.components.Facebook.*',),
and add appid andsecret key in your param
'params'=>array( 'Facebook'=>array( 'appId' => '148966221932337', 'secret' => 'a52ce7b4a0cd5d517c6ada53fc77cde7', 'cookie' => true, ),);
From you page you can call your Facebook SDK like this
$facebook = new Facebook(Yii::app()->params['Facebook']);$user_id = $facebook->getUser();
thank you.
I always try to store config variables in the DB. Especially if they involve a secret key. I would use Yii's crypt functionality and store it in the db. Then I would create model around retrieving config variables like that.
Secondly as far as the actual connection work and what have you, I would put that as a Component which extends CApplicationComponent, and either place the file in the extensions directory or the components directory. If you want to make it a true object. I think the helpers idea is a just a set a loose functions, mostly I use helpers for array and string work .
Kind of late, but I ended up downloading the Facebook SDK files with composer, autoloading those, and created a FacebookService extending CApplicationComponent that wraps the SDK.
So the main config is like
'facebookService'=>array( 'class' => 'FacebookService', 'appId' =>'xxxxxxxxxxx', 'appSecret' => 'xxxxxxxxxx', 'extendedAccessToken' => "xxxxxxxxxx", ),
and you can use it like
Yii::app()->facebookService->[method_I_defined]