[FX.php List] Returning FX Object From Function
Charles Ross
chivalry at mac.com
Fri Dec 9 19:53:21 MST 2005
I'm only slightly above beginner with PHP and an absolute beginner
with FX.php. If this question is more properly sent elsewhere, please
let me know.
I have three lines that are exactly the same for all of my php files
with the exception of one parameter (the layout name sent to SetDBData).
$instanceName = new FX($serverIP, $webCompanionPort);
$instanceName->SetDBData($fileName, 'WebAwardCategories');
$instanceName->SetDBPassword($webPW, $webUN);
For instance, here's my index.php file:
<?php
include_once('functions.php'); // includes the FX.php and
server_data.php files.
$instanceName = new FX($serverIP, $webCompanionPort);
$instanceName->SetDBData($laurelFile, 'WebAwardCategories');
$instanceName->SetDBPassword($webPW, $webUN);
$instanceResult = $instanceName->FMFindAll();
?>
<html>
<head>
<title>Testing</title>
</head>
<body>
Error Code: <?php echo $instanceResult['errorCode']; ?><br>
Found Count: <?php echo $instanceResult['foundCount']; ?><br>
<?php
foreach($instanceResult['data'] as $key=>$instanceData)
{
echo $instanceData['SubCategory'][0];?>
<br>
<?php } ?>
</body>
</html>
My thought was to create a function to perform these three lines of
code:
function NewFX($layout)
{
$fxphp = new FX($serverIP, $webCompanionPort);
$fxphp->SetDBData($laurelFile, $layout);
$fxphp->SetDBPassword($webPW, $webUN);
return $fxphp;
}
Then my index.php file becomes:
<?php
include_once('functions.php');
$instanceName = NewFX('WebAwardCategories');
$instanceResult = $instanceName->FMFindAll();
?>
<html>
<head>
<title>Testing</title>
</head>
<body>
Error Code: <?php echo $instanceResult['errorCode']; ?><br>
Found Count: <?php echo $instanceResult['foundCount']; ?><br>
<?php
foreach($instanceResult['data'] as $key=>$instanceData)
{
echo $instanceData['SubCategory'][0];?>
<br>
<?php } ?>
</body>
</html>
Loading the first version of this correctly finds 60 records and
displays the data from each of those records' SubCategory field.
Loading the second file results in an error:
Warning: Cannot use a scalar value as an array in /Library/WebServer/
Documents/Laurel/index.php on line 18
Line 18 is the foreach statement near the bottom of the file.
Is what I want to do possible? What am I doing wrong? Can PHP
functions not return an object?
Any help would be appreciated.
Thanks,
Chuck
More information about the FX.php_List
mailing list