Greetings,
I am facing problem with the afterInsert(). I am creating function like this.
function afterInsert(&$record)
{
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
//$record =& $app->getRecord();
$record = $record->val('id');
if ($record)
{
$res = mysql_query("SELECT * FROM requsition WHERE id = '".mysql_real_escape_string($record)."'",df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()));
$row = mysql_fetch_assoc($res);
echo gettype ($row['requisitions']);
echo "<pre>";
print_r($row['requisitions']);
foreach ( $row['requisitions'] as $vals)
{
$res = mysql_query ("INSERT INTO requsition_bak (
req_id,
requisition_no,
item_name,
pricePerUnit,
NoofUnits,
) VALUES
('".$row['id']."',
'".mysql_real_escape_string($row['requisition_no'])."',
'".mysql_real_escape_string($vals['items'])."',
'".mysql_real_escape_string($vals['pricePerUnit'])."',
'".$vals['unitCount']."')", df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()));
}
}
}
what I am doing is that I have one main table and one backup table. main table is. requsition and backup table is requisition_bak. I am inserting record to the main table first. in first table i have one field, name requisitions. for which i am using widget:type table, which insert records successfully in xml form. Now what i am doing here is that in afterInsert() function, i am trying to get the last inserted id, and then through this id i am retrieving records from requistion table to get requistions data of widget:type table and then parse it and insert it into the backup table, so that its easy for me while filtering. but this s throwing the following error.
Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\cvp\var\www\grants\tables\requsition\requsition.php on line 185
Catchable fatal error: Argument 1 passed to Dataface_IO::saveTransients() must be an instance of Dataface_Record, integer given, called in D:\xampp\htdocs\cvp\var\www\xata\Dataface\IO.php on line 687 and defined in D:\xampp\htdocs\cvp\var\www\xata\Dataface\IO.php on line 362
Also one more thing is that in afterInsert(), when i print_r the $record variable, it gives me nothing.
Kindly lead me.
Your help on the above will be greatly appreciated.
Thanks