Filemaker: Script which calls PHP code
How can I write a script which calls my PHP code? This script should contain re开发者_如何学编程cords which are in Filemaker Database.
You can use the "Insert from URL" script step to call PHP and make it do something. I was able to use this in a server-side script to call a PHP script with some params in the URL. This allowed me to have Filemaker talk to a PHP API of another service. Not sure if that answers your question (or if it is even still a question), but thought that I'd share.
I had a similar problem, where I wanted a FileMaker action to trigger a script that would alert a website that something had changed. I was working in FileMaker Pro 11 so Insert from URL
wasn't an option (though how I wish it had been)!
I created a FileMaker script called Sync and gave it one action: Perform AppleScript
(obviously this works on Macs only; you can achieve something similar using Send DDE Execute
in Windows).
In the Script Step Options, I set my Perform Applescript
to be a Calculated AppleScript
, and set it as follows:
"do shell script \"curl http://example.com/sync.php?id=" & Get( RecordID ) &
"\\\&layout=" & GetAsURLEncoded( Get( LayoutName ) ) & "\\\&table=" &
GetAsURLEncoded( Get( LayoutTableName ) ) & "\""
Note all the quotes and escaping of quotes.
To cause this to execute when something changes, go to File » Manage » Layouts and select the layout where a user might be editing a record, then click Edit
. In the resulting Layout Setup dialog, go to Script Triggers
and for the event OnRecordCommit
, select the Sync script you just created.
Now whenever a record is modified in that layout, the Sync script will run which executes the AppleScript which executes the shell command curl
, sending a GET request something to the effect of:
curl http://example.com/sync.php?id=123&layout=Edit%20Records&table=Records
From there, create a sync.php
to do something intelligent whenever it’s loaded, using $_GET['id']
and $_GET['layout']
and $_GET['table']
or similar passed-through variables.
One caveat with this approach is that FileMaker is frozen while the shell script executes, which in this case means until curl either receives a response or times out. While you can set the timeout to be very low (add arguments --output /dev/null --silent --head --fail --connect-timeout 1
), it still causes a delay to the user of a second or so, which can be noticeable if a user is editing lots of records. If anyone has a solution for this, or a way to cause the script to run asynchronously in the background, please let me know.
Yes, there is a PHP API available for FileMaker:
http://www.filemaker.com/downloads/pdf/article2_php.pdf
Before you work on adding coding for your own file, try getting the sample API code to work with the FMServer_Sample database.
精彩评论