Store
Community Documentation

v3 Knowledgebase

How to create an App

Apps are non-phpfox websites that interact with phpfox sites. An app is hosted in its own server and does not need any phpfox files.

Because of all this you are free to develop your app using any tools you want, ASP, python, mootools, jquery...

What I will do in this tutorial is to propose a structure for your app, try to give you a starting point to developing your own apps. Also I will be using PHP as the programming language but remember that you may choose any other programming language.
In this tutorial my PHPFox site is located at:
http://192.168.0.113/fox/svn/upload/

and my App is located here:
http://192.168.0.107/

In the PHPFox site, once you have created the app it will give you your "App Id", you will need this in your app to communicate with the PHPFox site:


In this example, the app is not hosted in the same server as the phpfox site, so when creating the app in the PHPFox site, in the tab "URL" you just need to fill the field "Frame URL" with the address to where your app can be found, in my case this is:
http://192.168.0.107
(dont forget the "http://" part)

You can find here a public gist illustrating a complete sample app:
https://gist.github.com/purefan/6318167

If you use the PHP library in that gist creating a simple and basic app is pretty easy. This library is not intended for production and is not feature rich, its purpose is to illustrate the process of posting a status update in the PHPFox site from the App.

To install this App please follow these steps:
1- In the PHPFox site create an app and note the App id (similar to the screenshot from above).
2- Upload the two files from the gist (link above) to your app server (not the one with PHPFox files)
3- In your app server open the file index.php
4- In this file fix the lines:
$oApp->setUrl('url to the PHPFox site');
$oApp->setAppId('your app id from when you created the App at the PHPFox site');

This is all. You should be able to go to the App in the PHPfox site and it would display the sample app, and allow you to update your user status from within the app.

Now, to a more in depth explanation of what is going on behind the scenes:

In the index.php file the first lines define the needed values for the app to be able to connect to the PHPFox site, such as the app id and the url to the phpfox site.

Then comes the HTML part, I used JQuery to make things easier, and wrote a small function to send an Ajax request to the same App server's index.php file, this ajax routine is very basic and does not check for errors, so if the server returns a 200 code it just assumes that everything went fine. There could be errors but this is a basic example, a step 1 for bigger things.

One interesting thing is the CSS include in the index.php file, it points to the PHPFox site and actually gets the relevant CSS file so the look in your app matches the look of the PHPFox site, this is one nifty trick that you may want to use for an easier blend.

Please post questions here about apps and I will answer as soon as I can.

I hope this quick article helps you understand better how to create Apps for PHPFox.