July 12, 201411 yr I'm playing around with the PHP API, and was converting a solution which was originally designed for IWP. The IWP version had an interesting design: the IWP user had access only to a single-record table with global fields. It would populate these fields, then run a script (which ran with full access permissions) which would do a custom search, and return values (if any) in the global fields. The reason it was designed this way was for security: the IWP user has zero access to the underlying data, which seemed like a smart design given all the issues with IWP (for example, if the user hits 'reload' they would often be moved to seeing record #1 in a given layout). Anyway, it turns out you can use this technique with PHP. The trick is to remember that PHP in filemaker doesn't use sessions. This means that global variables can be changed, and viewed, but only within a single PHP transaction. So the way to make this works is as follows: In FileMaker: * Set up a 1 record table with global fields and give the PHP user access to this table only. * Create a layout for this table and give the PHP user access to this layout only. * Create a script that takes scriptParameter, does a find, and returns data in the global field(s). Give the PHP user access to this script only. In PHP API: Use the findAnyRecord and setScript commands like this: $find=$fm->newFindAnyCommand($layoutName); $find->setScript("FilemakerPHPScriptToFindStuff", "apple,banana,pear"); $result = $find->execute(); $rec = $result->getFirstRecord(); $theResult = $rec->getField("gResultField"); Since the fields are globals, there's no worry about one PHP user stepping on another PHP user's data, either, even though they are both accessing the same 1 record table.
July 12, 201411 yr Interesting technique. I'm not finding a getFirstRecord() method in the API. Wouldn't it have to be $recs = $result->getRecords(); $rec = $recs[0]; or am I overlooking something obvious (as I often do)?
July 12, 201411 yr Author I have getFirstRecord : it's in FM_API_for_PHP_Standalone / FileMaker / Result.php but, as you point out, I don't see this defined in the PHP API guide : https://fmhelp.filemaker.com/docs/13/en/fms13_cwp_php.pdf
July 12, 201411 yr Yup, there it is in Result.php in FMS12, too! It's also found in /Library/FileMaker%20Server/Documentation/PHP%20API%20Documentation/index.html . Another fine example of FileMaker's red-headed stepchild, the PHP API documentation.
Create an account or sign in to comment