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.

Featured Replies

I feel like there is going to be a simple answer to this question but I'm not sure what to do. Is there some issue with using Filemaker objects in functions I create? Here is my issue. I have created a function in my PHP file so I can do some recursive operations. But when I try to do a new search in this function I am getting the error that my filemaker file is an undefined variable.


<?php

    require_once ('FileMaker.php');

    $fm = new FileMaker();

    $fm->setProperty('database', 'flow');

    $fm->setProperty('hostspec', 'http://localhost');    

    $fm->setProperty('username', 'admin');

    $fm->setProperty('password', 'admin');	





function notWorking($StaffID){

    $levelFind =& $fm->newFindCommand('Staff');

    $levelFind->addFindCriterion('relatedID', $StaffID);

    $search = $levelFind->execute();

    $thisLevel = $search->getRecords();

}



$findCommand =& $fm->newFindCommand('Staff');

$findCommand->addFindCriterion('relatedID', "=");

$result = $findCommand->execute();

$topLevel = $result->getRecords();

$test=$topLevel[0]->getField('StaffID');

notWorking($test); ?>







When the function is called I get the error about fm not being a defined variable. 





Notice: Undefined variable: fm 

Fatal error: Call to a member function newFindCommand() on a non-object 

If I try and put a new FileMaker object in the function it gives me an error that getField is not a defined function. Any thoughts?

I'm thinking that it's not grabbing FileMaker.php properly, so it doesn't know what a new "FileMaker()" is.

How are the permissions on FileMaker.php? Does "Everyone" have at least "read" access? This has bitten me before when hosting on OSX - if you paste the FileMaker.php file into your web directory, it won't have the right permissions by default; you have to set them. You'll want to do that on the FileMaker directory, too.

unless otherwise specified, variables inside of a php function have local scope .

i.e.


$var = "one";

function foo(){

	$var = "two";

	echo $var;  

}

function bar(){

	global $var;

	echo $var;  

	$var = "three";

}



echo $var; /* "one" */

foo(); /* "two" */

bar();/* "one" */

echo $var; /* "three"*/





you could just declare $fm global inside of notWorking().  A better way  might be to just pass the Filemaker object to notWorking()




function notWorking($StaffID, $fm)




if you're getting an error on 


$test=$topLevel[0]->getField('StaffID');

that states getField is not a function that means that $topLevel is not an array of record objects.

Also error checking ( Filemaker::isError() ) after every call to Filemaker will make troubleshooting much easier.

Edited by Guest
my grammer is aweful

  • Author

<?php

require_once ('FileMaker.php');

$fm = new FileMaker();

$fm->setProperty('database', 'flow');

$fm->setProperty('hostspec', 'http://localhost');

$fm->setProperty('username', 'admin');

$fm->setProperty('password', 'admin');

function getNextLevel($StaffID, $fm)

{

$levelFind =& $fm->newFindCommand('Staff');

$levelFind->addFindCriterion('zk_previous_f', $StaffID);

$search = $levelFind->execute();

$thisLevel = $search->getRecords();

if (FileMaker::isError($thisLevel)) {

$errorCode = $thisLevel->code;

if ( $errorCode == 401 ) {

return null;

} else {

echo "

Error: Level $StaffID - " . $thisLevel->getMessage() . "

";

exit;

}

} else {

return $thisLevel;

}

}

function printLevel($CurrentLevel, $fm)

{

$names = "

foreach ($CurrentLevel as $Person)

{

$name = $Person->getField('Name First') . " " . $Person->getField('Name Last');

$names .= "

" . $name . "";

$next = getNextLevel($Person->getField('zk_StaffID_p'), $fm);

}

echo $names . "

";

foreach ($next as $current){

if($current!=null){

printLevel($current, $fm);

}

}

}

$findCommand =& $fm->newFindCommand('Staff');

$findCommand->addFindCriterion('zk_previous_f', "=");

$result = $findCommand->execute();

if (FileMaker::isError($result)) {

echo "

Error: " . $result->getMessage() . "

";

exit;

}

$topLevel = $result->getRecords();

printLevel($topLevel, $fm);

?>

This part is a little weird it gets to $thisLevel = $search->getRecords(); and tells me this

Fatal error: Call to undefined method FileMaker_Error::getRecords() in /Library/WebServer/Documents/flow.php on line 17

That's not weird at all. Your find is throwing an error and your error checking is just a bit off. Try this




function getNextLevel($StaffID, $fm) {

	$levelFind =& $fm->newFindCommand('Staff'); 

    $levelFind->addFindCriterion('zk_previous_f', $StaffID);

    $search = $levelFind->execute();

    /*execute() will either return a Filemaker_Result Object or Filemaker_Error object*/

    if (FileMaker::isError($search)) {  

    	if ($search->getCode() == 401 ) {

        	return null;

        } else {

            echo "
Error: Level $StaffID - " . $search->getMessage() . "";

            return; /*just leave the function.  exit stops the script in it's tracks*/

        }

     } else { 

          return $search->getRecords(); /*just grabs the array or Filemaker_Record objects from the Filemaker Result Object*/

     }

        

}



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.