Scodigo, Inc.

Log In | Register

Cart Items:
0

Matching FileMaker/PHP Variables

Having worked with the SmartPill PHP plugin for a couple of weeks now, I'm finding I have a lot of code like this:

Let(
  [
    $Var1 = Table::Field1;
    $Var2 = Table::Field2;
    $Var3 = Table::Field3;
    ...
    PHPCode = ";
      $Var1 = fm_evaluate( '$Var1' );¶
      $Var2 = fm_evaluate( '$Var2' );¶
      $Var3 = fm_evaluate( '$Var3' );¶
      ...
    ";
  ];
  PHP_Execute( PHPCode )
)

Understand, the FileMaker variables are useful in a context other than the execution of the PHP code. Basically, I often have variables that store information needed by both FileMaker equations and PHP statements, and I would like a simple way to synchronize the two.

Has anyone had a similar problem and come up with a solution?

Thanks,Chuck

I don't get it

I must be missing something. How can smartpill read variables SET BY FILEMAKER... that is, I have a dozen or more things that I need to pass to smartpill. The way Chuck described above seems like the only way. Micah, your example and response addresses everything from the PHP side. I would like to be able to set a variable in FMPro using the Set Variable script step and have that variable accessable by smartpill. Possible?

I don't get it

Micah Woods's picture

Hello Scott,

fm_evaluate is probably the best way to get values from FM into your PHP code. Here's a code snippet that echoes the value contained in a FM variable named "$$SMART_PILL_VERSION".

// First we store our FileMaker expression
$expression = '$$SMART_PILL_VERSION';

// Now we use fm_evaluate to get the results of the expression
$value = fm_evaluate($expression);

// And then we echo it out
echo $value;

Regards,
Micah

Variable functions?

Micah Woods's picture

Hello Chuck,

Have you looked at the variable functions, for example fm_set_variable and fm_get_variable? See page 38 in the manual for details. This would allow you to use only one method for storing variables so syncing wouldn't be needed. Another advantage is that these variables are at the application level and thus are available in any file.

Another option, using a Let statement, you could use fm_evaluate within your PHP code to update the value of a FileMaker var. Here's a quick function to do that:

function var_sync($name, $value) {
if (!is_numeric($value)) $value = '"' . $value . '"';
$expression = "Let ( $name = $value ; \"\" )";
fm_evaluate($expression);
}

$myVar = fm_evaluate('$myVar');

$myVar = 'bar';

var_sync('$myVar', $myVar);

You can use this expression to test:

Let (
[
$myVar = "foo"
] ;
"Initial value: " & $myVar &
PHP_Execute ( PHP_Code ) &
"¶New value: " & $myVar
)

Regards,
Micah