Hi everybody,
I’m very new to Scriptcase, in fact this is my very first posting ever and I wish to contribute the following tip about callbacks in PHP (the Call_user_func_array). See the following call.
if(sendMail("<email@somewhere.com", "ENG",
"ACTIVATION", array($this, 'newregistrationmail'), $ar))
{
}
This calls a function that sends an email. The email subject and body is read from the database but it contains tokens. These are resolved by the callback. Since in SC the whole app is wrapped in an object it is paramount to use $this and then the method name (in this case ‘newregistrationmail’.
The last parameter $ar is an array containing the tokens to be resolved.
The following is the call
call_user_func_array($callback, array(&$subject, &$body, $tokens));
and the third one is the callback itself however the subject and body are passed by reference and the call also contains the variables as by reference otherwise you’ll get an error.
function newregistrationmail(&$subject, &$body, $tokens)
{
foreach($tokens as $token => $value)
{
$body = str_replace($token, $value, $body);
$subject = str_replace($token, $value, $subject);
}
}
Hope you can do something with this tip.
Cheers
Sparrow