Facebook & CodeIgniter – Definitive Guide

I spent more hours than the expected starting a simple development for a new Facebook application that runs on top of CodeIgniter. First I read A LOT, then I checked for solutions and, of course, I read a little bit more. After several hours reading and coding I knew it wasn’t good at all so I decided to start a new integration method from the scratch using only the code I found as guide. Here’s the result:

0. Environment

Before you get excited just review a few things before spent time reading another useless post :-)

  • PHP Version 5.2.6
  • MySQL 5 (It doesn’t affect Facebook integration at all but it is good to know)
  • HostMonster is my hosting provider (it is not a marketing initiative, just they have a nice environment set up for PHP)
  • Facebook platform 5 – I upload a copy of it to ensure you get the same copy I used.
  • CodeIgniter 1.6.3 – latest version available at the time of this post.

1. Do not hack CodeIgniter

I found a lot of solutions about hacking CodeIgniter by overriding functions or classes. NO, YOU DO NOT HAVE TO DO IT.

2. Install facebook library as plugin

  • Download the facebook platform ZIP
  • Unzip the files wherever you want -outside your Code Igniter application
  • Copy the WHOLE content under /php folder (under means files inside the folder and not with the container folder) to yout ./system/plugins folder inside Code Igniter application -Note: Yes, you have to include the jsonwrapper folder.
  • Rename the facebook.php file to facebook_pi.php

It is done! You already have installed facebook framework as plugin.

3. Autoload facebook plugin [optional]

To avoid the need of including the “load plugin” sentence inside every controller/class you can modify the ./system/config/autoload.php to include facebook plugin as required. It is almost a requirement for Facebook applications. Add to your $autoload['plugin'] array the facebook plugin. It could look like this:

$autoload['plugin'] = array('facebook');

Note: If you skip this step you will have to include the following line every time you need facebook functionality available.

$this->load->plugin('facebook');

4. Setup your application [updated]

Update your configuration file and set the ./system/application/config/config.php and change it as follows:

$config['uri_protocol'] = "PATH_INFO";
$config['base_url'] = "APPLICATION_URL";

Note: If you want to test your application locally, you can set base_url to http://127.0.0.1/path_to_your_app/

5. Extend your Controller class

Because I’m building a 100% facebook application, all my controllers require facebook API available. So I decided to extend my main Controller class as follows – BTW: By the date of this post the CodeIgniter documentation WAS WRONG about how to extend the core classes (CodeIgniter User Guide Version 1.6.3 – Creating Core System Classes). It is not true -i.e. it is false- that you have to extend the CI_ClassName. At least it didn’t work for me at all. Extend the ClassName directly.

Facebook Controller class should be placed under ./system/application/libraries folder.

Filename: XX_Controller.php (where “XX_” is the prefix you set on your ./system/application/config/config.php file – subclass_prefix parameter)

class FB_Controller extends Controller {
 
	// Facebook application key
	var $API_KEY = 'YOUR_API_KEY';
 
	var $facebook;
	var $uid;
 
	/*
	 * Custom Controller constructor.
	 * Adds Facebook support.
	 *
	 */
	function FB_Controller() {
 
		parent::Controller();
 
		// Authentication key
		$secret = 'YOUR_SECRET_KEY'; 
 
		// Prevent the 'Undefined index: facebook_config' notice from being thrown.
		$GLOBALS['facebook_config']['debug'] = NULL;
 
		// Create a Facebook client API object.
		$this->facebook = new Facebook($this->API_KEY, $secret);
		$this->uid = $this->facebook->require_login();
	}
}

Note: Inside the facebook application I built I always require an authenticated users, so that’s why I do have the require_login() call. However you can also validate if the user already have the application added. You should do this manually inside controller classes because there are a few exceptions where it is needed that user is authenticated but without adding the application.

6. Create your own controllers

Now you can extend your controllers from your Custom Controller. Note: You do not have to add any include or require sentence in your other classes, CodeIgniter will load directly your XX_Controller.php file -if it doesn’t load please check the config.php file and validate the subclass_prefix parameter.

Below you will find an example of a Controller that will validate if the user has the application added in his/her profile.

class Welcome extends XX_Controller {
 
	function Welcome() {
 
		parent::XX_Controller();
 
		// Check if the application has been added by the user
		try {
			if (!$this->facebook->api_client->users_isAppAdded()) {
				$this->facebook->redirect($this->facebook->get_add_url());
				return;
			}
		}
		catch (Exception $x) {
			// Clear cookies for your application and redirect them to a login prompt
			$this->facebook->expire_session();
			$facebook->redirect($this->facebook->get_login_url());
		}
	}
 
	// You should place your Controller's methods below.
 
}

7. Get out and celebrate

CodeIgniter is running as cleaner as you expected and Facebook API was included nicely!

I hope you find this post useful as I said at the beginning.

  PHP Client Library (34,3 KiB, 2.935 hits)


Web based project management tool

More than ten years I was forced to wait to see a real web based project management tool -by real I mean a decent software product that seems to address the PM needs and it is not a poor desktop application pushed to the web -like Microsoft Problem Server -oops I mean Project Server. Browsing the web I found the PMXPO 2008 and the SIIA CODiE Awards 2008 pages. Looking at the CODiE Awards 2008 finalists’ list I found @task, a company dedicated to deliver real software that uses the web.

I will try to get a demo or at least a try to that software product. As developer I know a lot of things about web development but also as PM I feel frustrated about the poor quality of the products delivered -that is one my personal reasons because I decided to start the SpZ Framework project. However, there are hope on new products that are jumping in and doing a great work.


Open UP project management – the discipline

According to the official OpenUP website the PM for a software development project that follow the OpenUP methodology is supposed to

  1. Encourage stakeholder consensus on prioritizing the sequence of work
  2. Stimulate team collaboration on creating long term and short term plans for the project
  3. Focus the team on continually delivering tested software for stakeholder evaluation
  4. Help create an effective working environment to maximize team productivity
  5. Keep stakeholders and the team informed on project progress
  6. Provide a framework to manage project risk and continually adapt to change

Points 1, 2, 5 are common to all PM in the universe, stakeholder management, expectation management and motivation management are part of the communication ability required as part of the role. However there are some other points that make me feel not so good:

Focus the team on continually delivering tested software for stakeholder evaluation

Stakeholder evaluation expression seems to be wrong. Stakeholder could be anyone with special interest in the project but not necessarily with decision power. Therefore, stakeholder is not the target of the deliverables for testing. More than one time you will be asked for “What if…” items, “Now that we already do this why…” items that everybody hate. Deliver & Deploy should be done only to the focus group -the right persons that will manage the results in an effective manner and following the software specs, probably an offshore QA team, a client QA or internal QA.

Help create an effective working environment to maximize team productivity

The working environment could be a lot of things, but probably means all external factors related for example to company environment, place/location and contractual stuff. However as IT and software developer I recommend to improve also the software environment -i.e. improve the software tools that the team use to do their work. I will recommend free/open source software :-) but obviously is not necessarily the situation for every project. Something that is common in the companies is to have tools but most of the m out of date, not legally acquired -at least in Colombia is a common practice- not working. As PM you should validate the work effort to build the software but also additional effort imposed by the use of the tools -even the time logger tool that I hope you use. If you will ask the team for additional tasks like time logging, change control documentation and other tasks related to software development and project management, be sure that they can do it fast and easy.

Provide a framework to manage project risk and continually adapt to change

A framework is a set of tools, for a person that is handling a project in progress in quite unfair to ask her/him for also the PM framework. In the most of the cases PM should ask the PM Office or the historical records of the company projects to get templates or at least examples. In the case there is no information available you will have to take a look to the templates available in the Internet :-) – I hope I can finish my templates soon so I can post them.

OpenUP site provides a lot of useful information but please validates it before use.


Integrated open source tools

PM should not have to deal with IT project strategy however almost all the time PM are “abandoned” in the middle of nowhere with a simple request: build a software tool that probably the client do not understand at 100% and it for sure is not documented.

The first steps are to (re)build the project scope and have a plan, but in the meanwhile your new team will need to have the tools to start their work. As PM you probably will have your own tools and templates but the team will have an IDE and that’s it. You should not deal with technical issues, but the reality is that as PM team will depend on you to get the right/optimal resources to simplify the developers work.

If you are those lucky guys that receive a software project since the beginning and not sometime after then you will have a better chance to get the right resources. My recommendation: Keep it simple but useful -even notepad is a useful tool if you use it correctly.

Your team needs:

  1. Deal with versions. Even before start your coding phase you MUST have a concurrent version system. In the market you will find a lot, but probably the common ones -and open source are: CVS and Subversion (a.k.a. SVN). Versions will force the team to work closer and with the same structure. If your IT team do it well, you will appreciate it a lot.
  2. Common IDE. Developers have their own affairs with specific IDEs. But you are the PM, ask your IT lead and force them all to use the same. I don’t like democracy, PM rules! However, as developer, I love Eclipse IDE.
  3. Documentation System. Most of the developers around the world will hate to document their code or applications. At least here in Colombia, when you ask developers to document their code or provide formal documentation they will give you the bad-eye look (in Spanish the malde’ojo) and you will understand that not the greatest documentation will be available at the end of the project. So provide the team with the tools to make this pain softer. I recommend only WYSIWYG tools like a Wiki, Google Docs, or any other fancy tool.
  4. Track their progress/work. Development tracking tools are suspiciously linked to Bug Tracking but it is not necessarily the truth. I’ve been using bug tracking tools like Mantis BT and Jira as Tasks Assignation tools. Keep in mind that a Bug is a request to do (fix) something. So why you cannot split your work packages in work items and assign them to the team -as you do with bugs.
  5. Provide test environments. I have to say this, why non-developer centric companies like Creative Agencies building Web applications do not understand that a Test Environment IS NOT the developer’s computer. What is this all about? What is the mystery? Test environments are needed, mandatory needed. Release building is a complex task that will have a lot of manually interactions -team pushing changes and enhancements- and it is NEEDED to have a place where to put all together and validate it before release it to a client -even to a client test environment. Please do not cut costs here. I will start a facebook group named “Why we do not have a test environment?” -BTW I do not like facebook, I do not even use it.
  6. Put it all together and working. This is the real thing about IT support. Install software is a piece of cake, is not a complex task, put all together and make it work smoothly is the key. So ask you IT team to do it, or do it yourself, like I did for some of my dev projects. There are many ways to integrate everything but I’m giving you some useful links to found the way to do it:

SpZ Team is currently designing an All-in-One integrated solution. For latest updates check the Framework page.


Open UP project management – Set your information system

Project managers who work in software development projects could be those who know about the software development process, probably because they were developers in the past, or those who do not have or do not want to have any technical knowledge and decide to delegate it to a third person -also know as Technical Director, Technical Lead, Team Lead, and other nice names for the man who really manage the software development process.

However this is an article for those who put their hands on projects, probably not coding but are PMs really involved in the software development process. I will explain how to set a project information system based on Open Unified Process and open source software.

The idea is simple, set a information repository accessible by anyone in the project, since the beginning of the development cycle to avoid miscommunication errors. The strategy, use a formal set of templates to document the business needs and the software design and publish them in a project site, but allowing the full access to the development team.

Before begin: you are the PM, if you do not want to go into the details ask IT team to handle the process, it is not so complicated but it takes time. It is not that easy

  • Share the information since the beginning
  • Software projects have this quality, share the information is good, all the information related to the software design and software implementation is good. There is no restriction, developers will understand better their work and BTW you will be reducing drastically the “developer” dependency -does this line sounds familiar to you? “I didn’t do it, I do not understand the code so it will take a time to do/fix/solve it“The easiest way to share documents is to have an open system that allows you to publish information in a public site -public means only to those person you want to have access. There are many ways to do -share a folder through the network :-( , share a folder through versions management system :-| , or to have groupware like Microsoft SharePoint. My case is to publish them since the beginning by setting a Wiki software that will have an ACL, a version management incorporated and all directly online -my team members do not have to install anything else than any web browser.Do not trust the model? Check the proved model by browsing Wikipedia. There is no bigger documentation team in the whole world.

    I will recommend for this experiment DokuWiki. It could be not the best, but is good enough. If you don’t like it there are hundreds so you can pick one. However I will recommend those with WYSIWYG editors to avoid the need of WikiSyntax.

  • Define what to share and how to share
  • At this point you know how to share whatever you will share. But, what is supposed to be shared? Many organizations already have their own set of standard documents, most of them because where certified in something. Like the ISO certifications. So, use them, do not worry, during the project evolution you will see how the documents grow and mature supplying with the appropriated information.Do not have template document? I see, you are on a small company or in a non-small-messy one. Don’t worry there are tons of templates available for free. ReadySET and Method123 will give you a hand but hey, you have to do your homework and build your own ones to fit your process and specific needs.

Know you are ready to start sharing your documentation. Give your team the freedom to work with the documents but track their changes, software design is not a democracy -brainstorming is a democracy where votes do not count. Software design is a Dictatorship where those who has the experience and knowledge will prevail.