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

liquidcms’s picture

and, 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

merlinofchaos’s picture

Status: Active » Fixed

The 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.

liquidcms’s picture

thanks 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

liquidcms’s picture

Title: content fields names don't make sense » row field variable names not created properly
Priority: Normal » Critical
Status: Fixed » Active

sorry.. 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.

liquidcms’s picture

hmm.. 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

merlinofchaos’s picture

Priority: Critical » Normal
Status: Active » Fixed

In general, using data in the $view->result object directly is a bad idea

For 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ih2502mk’s picture

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.

I 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.

ih2502mk’s picture

Got 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:

/*
 pre_render accepts view result as an argument see 
http://views.doc.logrus.com/classviews__handler__field.html#e30a1d9c98c62ae40c90b938e09cd0ec
for details (not like there is a lot of details...)
*/
$view->field[$id]->pre_render($view->result);
$output = $view->render_field($id, $row_number);