development

Rails Envy

The team at Rails Envy is back with their Apple-style commercials comparing Ruby on Rails to a variety of competing environments.

Note: These videos may only be funny to geeky web developers - especially Java and .NET haters, those who realize PHP is limited, and/or fanboys of Rails.

Ruby on Rails vs PHP


More Videos...
Ruby on Rails vs Java
Ruby on Rails vs .NET
Ruby on Rails vs PHP - Frameworks
Ruby on Rails vs PHP - Migrations
Ruby on Rails vs PHP - Organization
Ruby on Rails vs PHP - Changing Database

CakePHP and Facebook

CakePHP and Facebook

Do you want to integrate the Facebook API with CakePHP? Good news - it is really easy!

CakePHP is a free open-source rapid development framework for PHP. It's a structure of libraries and classes for programmers creating web applications originally inspired by Ruby on Rails. The primary goal is to enable you to work in a structured and rapid manner - without loss of flexibility.

In case you've been off the grid for the past few months, Facebook is a social utility that connects you with the people around you. It is like MySpace, only more about your friends, with more features, and less intrusive advertising.

After reading the only blog post on CakePHP and Facebook, I was left with many questions because I'm new to Cake. So I did some further Google searching and found how to build a photo gallery using CakePHP and Flickr, which utilizes Miguel Ros' Flickr component. This was exactly what I was looking for - a CakePHP component. Then it was just a matter of reverse engineering it to work with the Facebook API.

Here's the code...

Facebook Component
app/controllers/components/facebook.php

<?php
/**
* Facebook Component
* @author Matt Savarino
* @license MIT
* @version 0.1
*/
$GLOBALS['facebook_config']['debug'] = NULL;

class
FacebookComponent extends Object
{
    var
$api_key = "YOUR_API_KEY";
    var
$secret = "YOUR_API_SECRET";
   
    function
startup(&$controller)
    {
       
vendor('facebook/facebook');
       
       
$controller->facebook =& new Facebook($this->api_key, $this->secret);
       
$controller->set('facebook', $controller->facebook);
    }
}
?>

Sample Controller
app/controllers/nodes_controller.php

vendor('facebook/facebook');

class NodesController extends AppController
{
    var $name = 'Nodes';
    var $components = array('Facebook');
    ...
}

Accessing the API
The Facebook API is now available in both your controller and views.

Controllers: $this->facebook->api_client->users_getLoggedInUser()

Views: $facebook->api_client->users_getLoggedInUser()

Next Steps
I need to figure out the best method for forcing the user to install the application. The beforeFilter() function in the controllers seems to be the best place, but I'm having some issues.

Please comment with your questions/suggestions! I'll try to update this post with any improvements.


Copyright © Matt Savarino. Some rights reserved.
Syndicate content