Databuzz eNews – December 2008 Released

We’ve just released our eNews newsletter for December 2008. You can view it online at:

http://www.databuzz.com.au/enews/enews_122008_generic.html

If you want to be added to the newsletter mailing list just leave a comment below and we’ll add you to the list until our new automated subscription service is operational.

FileMaker API for PHP

It’s been over 2 years now since the FileMaker API for PHP public beta was first released, followed by it’s inclusion in FileMaker Server 9 (not Advanced which was a great decision to really get the technology widely adopted). I’ve done a lot of projects this year involving the FileMaker API for PHP to create web interfaces to backend FileMaker 9 databases, as well as upgrading some old .fp5/CDML sites to PHP API. Upgrading an old CDML site is great as you can accomplish so much more with PHP compared to the old proprietary CDML, and more often than not there is a great code snippet that you can reuse on the php.net site or other third party sites. I’ve been able to convert a 20+ page CDML site down to less than 10 pages with PHP, mainly through the use of include pages and variables.

FileMaker Server 9 ships with the PHP Site Assistant, which for anyone who worked with CDML and used the FileMaker Connection Assistant that was part of Claris Home Page, will see as it’s logical successor for the PHP API. It does a good job in creating a site in a matter of minutes (you can choose what type of site you require) and creates the necessary php pages and uses some nice looking CSS. However the more you use php pages generated by the Site Assistant the more problems you are likely to encounter in my experience. The php pages created by the Site Assistant are multi-purposed and have code for a number of requirements that you might not require (e.g. a record details page can be used to view, edit, delete or find). It also makes use of an include file – fmview.php – which is where things get really confusing. This php page has lots of php code to handle lots of different tasks and as you start to extend and customise the pages generated by the Site Assistant you are likely to butt heads with the fmview.php page as you try to understand what it’s trying to do.

Like me you’ll probably find extending pages generated by the Site Assistant problematic if you don’t want to rely on the fmview.php file, which is required for other functions. You quickly get to the point where you need to rewrite the pages from scratch so they don’t rely on the fmview.php page and you can have total control over each page and how it interacts with your FileMaker database. There’s also a few bugs with the php generated by the Site Assistant that you’ll have to deal with (e.g. in the recordlist.php page it creates navigation links for moving from one page to another in your found set of records, but the links overlap. For example it will have Record 1-20 on page 1, then Record 20-40 on page 2, and so on but it should be Record 1-20, Record 21-40 etc.)

Another alternative to generating PHP API pages quickly is FM Studio from fmwebschool. Like the Site Assistant it will generate the necessary PHP code for the PHP API and create your browse, find, edit, delete etc code for you. Like the Site Assistant you will also probably spend some time understanding how and why FM Studio does certain things and getting your head around the include files that are required.

Once your become familiar with the PHP code required you can hopefully get to the point where you can simply write the code yourself into your php editor (I use Dreamweaver). You’ll generally end up with cleaner and more concise code that you understand and can make sense of (don’t forget those comments!) without wondering why someone else did it that way.

Getting started with PHP does takes some time, like learning anything new. Here’s a list of some of the resources that I found useful in getting started with PHP in general and the new PHP API:

six.fried.rice blog article “Up to Speed with the FileMaker PHP API”

FileMaker Inc PHP Web Publishing Overview

Article in PHP Architect Magazine by Jonathan Stark – Part 1

Article in PHP Architect Magazine by Jonathan Stark – Part 2

FileMaker Custom Web Publishing with PHP PDF

VTC Training CD – FileMaker 9 PHP Foundations

jonathanstark.com – Jonathan Stark is the author of the Web Publishing with PHP and FileMaker 9 book

As well as Jonathan Stark’s book there is also another book I found useful that extends the content of Jonathan’s book – FileMaker Web Publishing: A Complete Guide to Using the API for PHP
By Allyson Olm, Stephen Knight, Michael Petrov. Both books come with sample code that you can open in your editor of choice and get hands on as you work your way through the chapters.

Note: as well as FileMaker’s official API for PHP there are some other alternative PHP API’s. Firstly there is FX.PHP which was around for many years before FileMaker’s PHP API was released. There’s also FM and PHP which I haven’t looked at yet.

Google Charts API and FileMaker

I’ve been spending most of my time over the past week or so working on integrating the Google Charts API into my upcoming FileMaker Pro CRM solution. For those not familiar with it the Google Charts API was released on December 6, 2007 and lets you dynamically generate charts via an HTTP request. So what’s in it for FileMaker developers? Well with the introduction of the Web Viewer in FileMaker Pro 8.5 you can now compose a chart request in your database and have it displayed on a Web Viewer on a layout. As the data changes the chart updates live. The chart is returned as a .PNG file. Here’s an example:

http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250×100&chl=Hello|World

You obviously require an active Internet connection to use this feature. Learning the API is pretty straightforward and most of the time will be spent getting familiar with the different charts available and the syntax required in the HTTP request, along with which data encoding method you will decide to use.

As I did more testing I was disapointed that, as the chart is a PNG file, I wasn’t able to use the new layout object resizing to resize the chart to expand/contract as the web viewer was resized, which is how I normally setup my web viewer layouts. So I decided to use the Troi URL plugin which is able to GET images from a website. As the URL appears in this format:

http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250×100&chl=Hello|World

you are not able to use that as is to retrieve the PNG file into a FileMaker container field. However there is a new switch in v2.0 and later of the plugin -“-ExtraImageCheck” – which when used with the TURL_Get function checks the returned data to verify if it is an image, even though there is no .png extension on the URL. Now I can set the container field to resize with the layout and the chart grows bigger and smaller – you don’t have control over the resolution of the PNG so it’s appearance will start to degrade as you increase it’s size (you do have control over the image size in pixels).

I’ve been quite impressed with the features of the Google Charts API. It was updated on March 20, 2008 with some new chart types (the maps one is pretty cool) and lifted the previous limit of 50,000 queries per user per day. FMWebschool have a sample (locked) file that you can download here that shows some of the options for FileMaker integration, along with 2 movies here and here. If you know what data you are charting and what chart types you prefer you should be able to integrate Google Charts pretty quickly into your FileMaker Pro solution. Whilst not offering as many features as some of the charting plugins available you can’t complain about the price.

A great future enhancement of the Web Viewer in FileMaker Pro would be the addition of another option for “Google Charts” to make setting up a web viewer to display Google Charts even easier.

Andrew Duncan