FileMaker Server XML API Adapter
SimpleFM is a fast, convenient and free tool designed by Soliant Consulting, Inc. to facilitate connections between PHP web applications and FileMaker Server.
SimpleFM is an ultra-lightweight PHP5 package that uses the FileMaker Server XML API. The FMS XML API is commonly referred to as Custom Web Publishing (CWP for short).
See also, the SimpleFM_FMServer_Sample demo application which illustrates use of SimpleFM in the model layer of an MVC Zend Framework 2 application.
- Returns a PHP array. The result parser inside SimpleFMAdapter uses PHP5's SimpleXML.
- Can be used on it's own or with any service class, such as Zend\Amf, Zend\Rest, and Zend\Soap.
- Easily see the underlying API command formatted as a URL for easy troubleshooting
- Use the convenient errorToEnglish function to interpret FMS error codes
SimpleFM is a single class with less than 1000 lines of code. While SimpleFM was written with simplicity as the main guiding principle, it also perfoms well. We have informally benchmarked it, and obtained faster results for the same queries compared to the two most common CWP PHP alternatives.
SimpleFM, the examples and this documentation are tailored for PHP 5.5 and FileMaker Sever 12
- PHP 5.5+
- FileMaker Server 12+
With minimum effort, you could get them to work with PHP 5.0 (requires SimpleXML) and any version of FileMaker server that uses fmresultset.xml grammar, however, backward compatibility is not maintained.
SimpleFM is free for commercial and non-commercial use, licensed under the business-friendly standard MIT license.
All the examples included with SimpleFM are based the FMServer_Sample which is included with FileMaker Server 12. To use the examples it is assumed that you have FMServer_Sample running on a FileMaker 12 host with XML web publishing enabled. (You may also have any other FMS services enabled, including PHP web publishing, but only XML is required for SimpleFM.) Setup and configuration of FileMaker server is beyond the scope of this documentation.
/documentation/fms12_cwp_xml_en.pdf for the official FileMaker documentation. In particular, Appendix A (page 43) contains a useful command reference.
WARNING: Copy/paste out of the pdf documentation must be done with caution. The typsetting uses emdash, not hyphen characters. They look very similar, and this can be very hard to troubleshoot if you are not careful.
/documentation/simplefm_example.php for a working PHP example that follows the basic steps shown in this Quickstart section, as well as some additional tips about usage.
$hostConnection = new HostConnection( 'localhost', 'FMServer_Sample', 'Admin', '' );
$adapter = new Adapter($hostConnection);
/** * @Note: See fms12_cwp_xml_en.pdf Appendix A for a complete command reference. * Commands that take no arguments, such as -findall, must be set with either a * NULL value or an empty string. * * @WARNING: Copy/paste out of the pdf must be done with caution. The typsetting * uses emdash, not hyphen characters. They look very similar, and this can be * very hard to troubleshoot if you are not careful. */ $adapter->setCommandArray( array( '-max' => 10, '-skip' => 5, '-findall' => NULL ) );
$result = $adapter->execute();
$url = $result['url']; // string $error = $result['error']; // int $errortext = $result['errortext']; // string $errortype = $result['errortype']; // string $count = $result['count']; // int $fetchsize = $result['fetchsize']; // int $rows = $result['rows']; // array
Portals are returned as named child arrays to every record in the fetched set. Be careful about adding portals to your web layouts, as all associations are loaded eagerly, and this could bloat your result array. SimpleFM can't take advantage of techniques like lazy loading that help mitigate performance issues with large related data sets in ORMs like Doctrine, so it is up to the developer to tailor the web layouts appropriately for best performance.
There can be more than one portal on a layout. SimpleFM returns n portals for every record in the found set.
Assuming you leave rowsbyrecid as FALSE (the default setting), here is example array notation that would echo the the recid and the field value from the first portal row on the first record in the result set. Note that index, recid and modid are always properties on every parent and child row.
echo $rows['Portal_TO_Name']['rows']['recid'].'<br>'; echo $rows['Portal_TO_Name']['rows']['myField'];
If you set rowsbyrecid to TRUE on your adapter, here is syntax that would echo the data from a portal where the parent row has recid 154 and the child row has recid 335932.
It is left to you do decide which way you want the results indexed.
FileMaker supports a field configuration called "Repeating". If the field is defined as repeating in the FileMaker schema, but the layout associated with the request only defines a single repetition, SimpleFM will treat it like a normal field. Assume a repeating field named myRepeatingField is defined with three repetitions, containing the following three values in each repetition, respectively:
// If the layout only defines one repetition for the field echo $rows['myRepeatingField']; // output: // Foo
// If the layout defines more than one repetition for the field echo $rows['myRepeatingField'] . <br>; echo $rows['myRepeatingField'] . <br>; echo $rows['myRepeatingField']; // output: // Foo // Bar // Baz
Note that FileMaker repetitions, are 1 indexed, and of course php arrays are 0 indexed, so repetition 1 is
$myRepeatingField and so on.
In particular, you will need to understand qualified field name conventions in order to set repetitions (other than 1) on repeating fields.
If you leave off the repetition number when setting fields in your commandArray, it defaults to setting repetition 1.
$adapter->setCommandArray( array( 'myRepeatingField' => 'Foo', 'myRepeatingField(2)' => 'Bar', 'myRepeatingField(3)' => 'Baz', '-new' => NULL ) );
Included in this library is a gateway adapter for ZF2. This gateway includes
These functions take an array of commands. Any command not prefixed with a hyphen is considered a search query. by default search queries are executed as a LIKE. If you want to search for an exact match prefix your criteria with ==.
$gateway->findBy([ 'field1' => '==value1', 'field2' => 'part' ]);
This query will search for field equal to
value1 and all values of
field2 which contain the string
See more details in the official API Documentation Appendix A (page 45):
Note that to be accessible, fields (and field repetitions) must be on the layout you specify in the query.
See the SimpleFM_FMServer_Sample demo application which illustrates use of SimpleFM in the model layer of an MVC Zend Framework 2 application.