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.