Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP API and Global Variables

Featured Replies

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.

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)?

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.