Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.3
Component:
Views Data
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Mar 2009 at 08:14 UTC
Updated:
28 Oct 2010 at 17:41 UTC
I am really trying to just get the "items" from my view (i so miss the views_build_view() command :( ); best i seem to be able to do is this:
$view = views_get_view('get_expert_profile');
$view->execute_display('default', array($variables['field_expert'][0]['uid']));
$expert_profile = $view->result[0];
which returns this:
$view->result
: array =
0: object(stdClass) =
nid: string = "28"
node_data_field_expertblog_field_expertblog_url: string = "www.myblog.ca"
node_data_field_expertblog_field_expertblog_title: string = "John's Blog"
node_data_field_expertblog_field_expertblog_attributes: string = "N;"
node_data_field_expertblog_nid: string = "28"
node_type: string = "expert_profile"
node_data_field_expertblog_field_accreditation_value: string = "Phd. Child Psychology"
node_title: string = "John Sayles"
ideally i would really like to get the link field as it appears in the views preview - an A tag build correctly for me; but i guess that's not likely possible,
but, the point of this issue.. sorry.. is what's with the field names: why does field_expoertblog show as an added extension in all the cck field names?
the names should be, in case not obvious:
node_data_field_expertblog_url
node_data_field_expertblog_title
node_data_field_expertblog_attributes
node_data_field_accreditation_value
Comments
Comment #1
liquidcms commentedand, to make it worse, if i move the accreditation field above the expert_blog field, all the field names change to now have field_accreditation in the beginning of the name
Comment #2
merlinofchaos commentedThe field names are automaticlaly aliased as $table . '_' . $name -- and the $table, in CCK's case, is an alias. (A rather too long one, IMO, but that' what CCK picked). This is partially historical; at this point, Views is so good about alias collision that it really isn't necessary to use that default anymore, so maybe it could be changed.
If you want to get the field as it appears, you can use:
$output = $view->render_field('field_id', $row_number);
The field ID will be much shorter. You can also find field IDs from the Theme: Information page.
In general, using data in the $view->result object directly is a bad idea, and if you can avoid it you should. Views does not guarantee that the naming structure it chooses will remain consistent, especially if fields are added or the order of fields is changed. Collisions can cause automatic renaming.
Finally, if you don't want a rendered view, you can use $view->pre_execute(); $view->execute(). The view will be executed but none of the rendering will have run.
Comment #3
liquidcms commentedthanks earl, i'll try it out .. and see if it makes sense - doesn't right now.
right up to that point the whole fields views, preprocess function, tlp file seems very intuitive - simply have variables available in the preprocess function that match the field names - i guess for related fields (which is the coolest addition of all to views - by far!!) there needs to be var name massaging.. like $relationship_name _ $field_name; but other than that don't get why var isn't field name..
but i'll check out render_field idea.. of course this sounds like more sql calls since i DO already have the field data available in my preprocess call
Comment #4
liquidcms commentedsorry.. had to re-open.. for 2 reasons - 1. this is annoying as hell and can't possibly be design intent and 2. i think possibly you didn't notice quite what i was saying.
in row tpl i get a $variables['row'] object.. which has all the info i had the view put in there.. perfect. but, the field names aren't based on the table name; they are concatenated with the name of the field that comes earlier in the list.. which i am sure must be a bug. It is perfect that the tpl has the value of my variables i am putting in there but the fact that i can't access them consistently (i.e. if i re-order my fields the var names all change) can't be right.
example from above:
field 1: node_data_field_expertblog_field_expertblog_title
field 2: node_data_field_expertblog_field_accreditation_value
the name for the accreditation field is based on the name of the field expertblog only because that field came first; nothing to do with any table.
Comment #5
liquidcms commentedhmm.. although maybe what you were getting at is that the variables also seem to be in the $fields array and name better (but not accessible in the preprocess function.. only the $variables are
Comment #6
merlinofchaos commentedFor most templates, and unfortunately I was an idiot and failed to be consistent about this, $variables['rows'] is $view->result. (There are some where it overwrites the raw data and replaces it with finished data, and that was an error that is too late to change now). So perhaps I failed at making clear that $rows == $view->result and you are not guaranteed that those names will stay the same. You are guaranteed that field IDs will not change, and that's why using data in the $fields array (in the case of that template) is always superior.
Comment #8
ih2502mk commentedI have slightly the same problem as OP and your approach would work for me except for one issue: I can't get multiple CCK fields rendered this way.
Comment #9
ih2502mk commentedGot it done. I found out that multiple fields (grouped multiple fields to be more specific) are actually rendered in by pre_render() method of views handler. So in my case it ws like that: