Hi,
As you know Facebook doesn’t have develop mode to that allow you to work locally.
But there is way to do it – and its very easy to deployment.![]()
First create 2 applications on Facebook, one for “dev” and one for “production”.
In dev application set you application url to the locally localhost if “127.0.0.1″ like:
http://127.0.0.1/your_app.
The second step is to create two “environments” in your application – “dev mode” and “production mode”.
Create a settings class that check if you work locally and return the Facebook API Key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php class ApplicationSettings { private static $facebook_api = array( "dev"=>array( "key"=>"123", "secret"=>"123" ), "prod"=>array( "key"=>"123", "secret"=>"123" ) ); public static function get_facebook() { if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { return self::$facebook_api["dev"]; } return self::$facebook_api["prod"]; } } ?> |
Set your Facebook API Key and Secret to the “dev” and “prod” modes.
Now we will change the way we connection to facebook api to get the
settings from our new class.
1 2 3 4 5 6 7 8 | <?php $facebook_settings = ApplicationSettings::get_facebook(); $facebook = new Facebook(array( 'appId' => $facebook_settings["key"], 'secret' => $facebook_settings["secret"], )); ?> |
Now every time we connect to Facebook API the settings class will
check our domain and if we work on “127.0.0.1″ its automatically
gets the “dev mode” API that pointed to our local application.
Have Fun ![]()
Garry Lachman


Anonymous functions now available from PHP 5.3
Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses.
Example:
2
3
4
{
echo "My name is $name";
};
Or you can use it as callback like javascript
2
3
4
5
6
7
8
9
10
11
12
"first_name" => "Garry",
"last_name" => "Lachman",
"age" => "27"
);
$callback_function = function ($field, $field_value)
{
echo "$field = $field_value";
};
array_walk($arr, $callback_function);
Using variables out function scope
2
3
4
5
6
7
8
9
10
11
12
13
14
$arr = array(
"first_name" => "Garry",
"last_name" => "Lachman",
"age" => "27"
);
$callback_function = function ($field, $field_value) use ($prefix)
{
echo "$prefix $field = $field_value";
};
array_walk($arr, $callback_function);
Have fun boys & girls