[support] Unserializing Data for Use in a View
Metzler, David
metzlerd at evergreen.edu
Thu Sep 2 20:31:01 UTC 2010
I'm not an expert here, but I'm reading the coments differently than you
are.
I think you should be working with $row->data ( or at least $row) and
not with $output. That's got html in it, right?
Dave
________________________________
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Shai Gluskin
Sent: Thursday, September 02, 2010 1:24 PM
To: support at drupal.org
Subject: [support] Unserializing Data for Use in a View
I'm creating a view of ubercart order products. I got the necessary data
to be accessible to Views using Table Wizard
(http://drupal.org/project/tw).
The product attribute info is stored serialized in the "data" field on
the uc_order_products table. Here is an example of the raw serialized
data:
a:5:{s:6:"kit_id";s:3:"570";s:6:"module";s:14:"uc_product_kit";s:10:"att
ributes";a:2:{s:9:"Attending";a:1:{i:0;s:26:"Jane Doe, John
Doe";}s:4:"Note";a:1:{i:0;s:45:"We are friends of Eric Smith and Sandy
Smith";}}s:9:"shippable";s:1:"0";s:9:"unique_id";s:23:"4c7d632a8090c7.95
333579";}
I have no problem printing it out like above.
Unserialized it looks like this:
Array
(
[kit_id] => 570
[module] => uc_product_kit
[attributes] => Array
(
[Attending] => Array
(
[0] => Jane Doe, John Doe
)
[Note] => Array
(
[0] => We are friends of Eric Smith and Sandy Smith
)
)
[shippable] => 0
[unique_id] => 4c7d632a8090c7.95333579
)
I want to print out: Jane Doe, John Doe
Here is what views-view-field.tpl.php has to say:
// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos
Exp $
/**
* This template is used to print a single field in a view. It is not
* actually used in default Views, as this is registered as a theme
* function which has better performance. For single overrides, the
* template is perfectly okay.
*
* Variables available:
* - $view: The view object
* - $field: The field handler object that can process the input
* - $row: The raw SQL result that can be used
* - $output: The processed output that will normally be used.
*
* When fetching output from the $row, this construct should be used:
* $data = $row->{$field->field_alias}
*
* The above will guarantee that you'll always get the correct data,
* regardless of any changes in the aliasing that might happen if
* the view is modified.
*/
This is what I'm putting in views-view-field.tpl.php:
$data = unserialize($output);
print $data['Attending'][0];
Nothing gets returned.
What am I doing wrong?
thanks,
Shai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20100902/11ea3f91/attachment-0001.html
More information about the support
mailing list