xochi Posted July 12, 2014 Posted July 12, 2014 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.
doughemi Posted July 12, 2014 Posted July 12, 2014 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)?
xochi Posted July 12, 2014 Author Posted July 12, 2014 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
doughemi Posted July 12, 2014 Posted July 12, 2014 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.
Recommended Posts
This topic is 4080 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now