custom action

Archived from the Xataface Users forum.

wisni1rr — Thu Mar 22, 2012 12:15 pm

I have the following to make a printable report. I need to modify it so it will only pull the current record (This action is pulling the entire query rather than the record in details view [this report link is only viewable on the current record details screen])

Code: Select all
<?php class actions_printable_report {     function handle(&$params){         $app =& Dataface_Application::getInstance();         $query =& $app->getQuery();                 if ( $query['-table'] != 'GENERAL' ){             return PEAR::raiseError('This action can only be called on the Listing table.');         }                 $GENERAL = df_get_records_array('GENERAL', $query);            echo '<html><head>'             .'<title>BWA Report v1.0</title>'             .'<style type="text/css">'             .'    th { font-size: 60%;}'             .'    td { font-size: 60%;}'             .'    img { width:300px;                         height:145px;                         border-style:ridge}'             .'    img.logo { width:75%;                              height:100%;                              border:none }'             .'</style>'             .'</head>'             .'<body>';

Thanks for taking the time to read my post!


shannah — Thu Mar 22, 2012 2:14 pm

Change

Code: Select all
$GENERAL = df_get_records_array('GENERAL', $query);

to

Code: Select all
$GENERAL = df_get_record('GENERAL', $query);

-Steve


wisni1rr — Fri Mar 23, 2012 10:41 am

Thanks, Steve!

I have changed the code as you have instructed.

Now the very next line in the code throws an error:

Code: Select all
foreach ($GENERAL as $record){                    $Address = $record->htmlValue('StreetNo').' '.$record->htmlValue('StreetName').' '.$record->htmlValue('City').', '.$record->htmlValue('State').' '.$record->htmlValue('Zip');

Fatal error: Call to a member function htmlValue() on a non-object (points to line with $Address = …)

The code works just fine when I call the records_array, It just cycles through all that are in the list view.

Thanks for your help!


shannah — Fri Mar 23, 2012 12:33 pm

Yes. df_get_record() returns a Dataface_Record object directly - not an array of records. You don’t need to loop through them anymore with a foreach loop.