kmcook
Posts: 6
|
| Posted: 11/11/2004, 6:12 PM |
|
PHP gurus - can someone educate me and explain why is this failing?
I'm using a checkbox list, and have it working satisfactorily on test forms.
But, there's a lot of hardcode in the examples and I wish to convert the Before Show code
and the CCS examples xxxModify($Actions) code into udf calls.
PHP is new to me and I'm a bit nonplussed why I get errors here.
My intersect table for the Checkbox control is named ANTENATAL_TESTS with fields ANTTEST_ANTTEST_ID, PREGNANCY_PREGNANCY_ID.
The form named PREGNANCIES will be passed a (numeric) parameter PREGNANCY_ID, and the checkbox control in the form is named chkList1.
In the 'custom code' Before Show event of the record form I have
//Custom Code @10-D7FDCE23
// -------------------------
global $PREGNANCIES; // this inserted by CCStudio generator
chkListShow("Peri", "PREGNANCIES", "chkList1", "PREGNANCY_ID", "ANTENATAL_TESTS", "ANTTEST_ANTTEST_ID", "PREGNANCY_PREGNANCY_ID");
// -------------------------
//End Custom Code
At the bottom of the events script I have this function.
function chkListShow($Connection,$FormName,$ControlName,$PassedParam,$TableName,$Field1,$Field2)
{
// set connection and arrays
$connPrefix = "clsDB";
$NewConn = $connPrefix.$Connection."()";
$TempArray = array();
$ThisConnection = null;
// populate the multiselect checkbox list in $ControlName
if ($FormName->EditMode) {
// create a new connection object
$ThisConnection = New $NewConn;
$ThisConnection->query("SELECT ".$Field1." FROM ".$TableName." WHERE ".$Field2." =".$ThisConnection->ToSQL(CCGetParam($PassedParam,0),ccsInteger));
while($ThisConnection->next_record()) {
array_push($TempArray,$ThisConnection->f($Field1));
}
$FormName->$ControlName->Multiple = true;
$FormName->$ControlName->Value = $TempArray;
// close and destroy recordset
$ThisConnection->close();
}
}
************
1. PHP chokes on the $ThisConnection = New $NewConn line
Quote :PHP Fatal error: Class 'clsDBPeri1()' not found in path\Preg_events.php on line xx .
2. If I hardcode the connection as -
$ThisConnection = New clsDBPeri1();
the script does not choke and continues.
Plainly I have a serious misundertanding of how PHP evaluates $NewConn??
3. When the connection is left hardcoded, to enable testing the code further, no errors are reported
but when displayed in the browser, the checkbox list has all checkboxes unchecked, for any record,
when some checkboxes should be checked in each case.
That is the lines
$FormName->$ControlName->Multiple = true;
$FormName->$ControlName->Value = $TempArray;
appear invalid too.
Anyone able to set me straight...???
TIA
Casey.
|
 |
 |
mrachow
Posts: 509
|
| Posted: 11/12/2004, 12:13 AM |
|
Without looking at anything else
things like
$FormName->$ControlName->Value
should be
$FormName->ControlName->Value
Regards,
Michael
_________________
Best regards,
Michael |
 |
 |
Casey
|
| Posted: 11/13/2004, 9:59 PM |
|
.??.. but $ControlName contains the passed in name of the control..??
...any else ..??
Casey
|
|
|
 |
mrachow
Posts: 509
|
| Posted: 11/14/2004, 10:21 AM |
|
Pracmatically spoken only the first part of such a reference chain looks like a common variable.
Have a fast look at the component reference how things are refered.
Correct this first and look further...
Kindly regards,
Michael
_________________
Best regards,
Michael |
 |
 |
Casey
|
| Posted: 11/14/2004, 4:50 PM |
|
Hi Michael,
Thanks for the responses, but I think you are missing the point of my query - I may not have been clear enough.
I want to be able to have the connection and component references subsitutable, i.e., use passed in values, thus I am trying to use variables in all references.
I do have forms working correctly with the CCS example code as a pattern to follow, but it relies on hardcoded connection, table, column and parameter values - I'm attempting the example Before Show and Modify code as a function.
....Unresolved....but thanks for replies.
Casey.
|
|
|
 |
lvalverdeb
Posts: 299
|
| Posted: 11/16/2004, 9:05 AM |
|
Casey,
Here's how I accomplish similar functionality (that is if I understood your question correctly ). I am not sure if this is what you need but object references are substitutable as long as the property names are equivalent.
1) Pass the $Connection and other parameters as objects i.e.:
chkListShow(new clsDBYourConnectionName(),$YourForm,$YourForm->YourCheckBox,$PassedParam,$TableName,$Field1,$Field2)
Note that the full path to ControlName i.e the checkbox is passed to the function since the checkbox is contained in a form object.
2) The function should accept parameters by reference and by value:
function chkListShow($Connection,$FormName,&$ControlName,$PassedParam,$TableName,$Field1,$Field2)
add an ampersand to the object references which you'd like the function to change a value.
After implementing these changes, your function would look like this:
function chkListShow($ThisConnection,$FormName,&$ControlName,$PassedParam,$TableName,$Field1,$Field2)
{
// set connection and arrays
$TempArray = array();
// populate the multiselect checkbox list in $ControlName
if ($FormName->EditMode) {
// create a new connection object
$ThisConnection->query("SELECT ".$Field1." FROM ".$TableName." WHERE ".$Field2." =".$ThisConnection->ToSQL(CCGetParam($PassedParam,0),ccsInteger));
while($ThisConnection->next_record()) {
array_push($TempArray,$ThisConnection->f($Field1));
}
$ControlName->Multiple = true;
$ControlName->Value = $TempArray;
// close and destroy recordset
$ThisConnection->close();
}
}
I hope this helps.
Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4 |
 |
 |
lvalverdeb
Posts: 299
|
| Posted: 11/16/2004, 9:22 AM |
|
Also, at the end of the function, add:
return $ControlName;
This returns the $ControlName with the modified property values.
Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4 |
 |
 |
Casey
|
| Posted: 11/16/2004, 1:45 PM |
|
Luis,
Thank you - appreciate your response.
I've learned two new techniques from your code, thanks.
Casey.
|
|
|
 |
|