“Packing” a Dataface Records object
Archived from the Xataface Users forum.
gthorne — Thu Aug 09, 2012 3:29 pm
So, I’m moving along on my custom dashboard page. I have some data normalized across a few tables, so I went from this:
- Code: Select all
$events = df_get_records_array('calendar', array()); df_display(array('events'=>$events), 'dashboard.html');
To this:
- Code: Select all
- `` $result = mysql_query (“SELECT
event_start_time,event_end_time,short_desc, maint_types.description AS maint_type, vendors.vendor_name AS vendor_name, “.
”trouble_ticket_number, personnel.personnel_name AS assigned_to,city, states.postal_abbr AS state,notes,submitted_by,submitted_date“.
”FROMcalendar“.
”LEFT JOIN maint_types ON ( calendar.type_id = maint_types.type_id ) “.
”LEFT JOIN personnel ON ( calendar.assigned_to_id = personnel.personnel_id ) “.
”LEFT JOIN states ON ( calendar.state_id = states.state_id ) “.
”LEFT JOIN vendors ON ( calendar.vendor_id = vendors.vendor_id )”, $app->db());while ($row = mysql_fetch_assoc($result))
{
$events[] = $row;
}df_display(array(‘events’=>$events), ‘dashboard.html’); ``
But now, it’s no longer a DF Recordset object, so member functions like ‘getURL’ don’t work anymore. Am I going about this the right way? Is there a way to just ‘pack’ the recordset object with my array once I get it? Or am I missing out on some DF function that is equivalent to mysql_query but returns a Recordset?
Thanks again.
shannah — Thu Aug 09, 2012 3:35 pm
- Code: Select all
$evt = new Dataface_Record('calendar', $row);
shannah — Thu Aug 09, 2012 3:36 pm
Although, this object will only have the values that are in $row… You need at least the primary key to be in there for things like getURL() to work correctly.
gthorne — Thu Aug 09, 2012 4:18 pm
So a Dataface_Record is just a single row?
- Code: Select all
while ($row = mysql_fetch_assoc($result)) { $evt = new Dataface_Record('calendar', $row); $events[] = $evt; }
shannah — Thu Aug 09, 2012 4:31 pm
Yes.
gthorne — Thu Aug 09, 2012 5:01 pm
I guess I should’ve just tried it instead of asking.
One last issue. Now $evt->val(‘state’) doesn’t work in the {foreach} loop. The val() call works for all native fields, but not for the fields I got out of the JOIN. I’m not a Smarty expert, so this is probably something easy that I’m missing.
gthorne — Thu Aug 09, 2012 5:49 pm
Just verified that the _values array in the Dataface_Record object only has keys for the fields in the selected table.:
- Code: Select all
id => 1 event_start_time => Array event_end_time => Array short_desc => Test event city => Arlington notes => Test event submitted_by => Jon Smith submitted_date => Array type_id => vendor_id => assigned_to_id => state_id =>
shannah — Thu Aug 09, 2012 7:27 pm
Yes. It encapsulates a single row of the table specified in the first parameter of the constructor. val() only works for:
- Fields of the table.
- Grafted fields.
- Calculated fields.
- Transient Fields
Some of the values from your query you’ll need to use directly from the $row result.