Views is splendid and powerful, no doubt about that. Sometimes, however, there is a need not so much for a full View, but for a (sorry for the pun) pre-View.
Time to clarify. What I am looking for, is a View (of some sort) which does Not show me full results in a table, a grid or whatever, but which delivers just some “raw input”, e.g. just an array of node nids. With that array, I would then continue to do my own stuff in my own PHP.
Can Views be tweaked in such a way that it delivers nothing visible, but just an array of, say, nids? That view could then be included in a node, pumped into a variable, and then I can continue with my own PHP. So, something like:

$x_array = get-some-array-from-some-view(view_id);
$y = my_nifty_homegrown_php_function($x_array);

Can this be done?

Comments

modul’s picture

Thanks for your reply, Ayesh, but I don't think that module does the trick. It adds a new type of Display in your Views environment itself, but I don't think it actually meddles with the result of your View. It looks helpful in the View development process, but that is not really what I'm after. I would like Views to OutPut an array of results, with which I can then do my stuff, e.g. in a PHP-enabled node, in which the View has been inserted.
Anyone has any idea?

shura80’s picture

You could simply take note of the output in the preview to copy the Views generated query in a module, block, etc..., than use it and edit it at your needs.

modul’s picture

Hi Shurah, and thanks for your reply, but no, that is not the idea.
- I have a node, which is PHP-enabled.
- In that node, I insert a view - which, ideally, should provide me with an array.
- With that array, I would like to continue with my own PHP.

Can that be done?

ayesh’s picture

I'm not sure I got what you tried to ask right.

You can also try to do your own PHP work in tpl.php files.
In the View, go to theme information and you can see tpl.php file suggestions for row, whole view, display, etc.
Some of these tpl.php files have the whole results output (not the all results within pages). So you can do your PHP work there.

modul’s picture

Hi Ayesh, maybe I did not explain my situation sufficiently clear. Once again, in brief:
I have a node, which is PHP enabled. My PHP code has already been written. Only thing: it needs input, at the moment when a visitor checks out my node. At that moment, I am trying to have a View become active, in order to (and here is my question mark) cough up an array. My PHP code in that node will then gladly accept that array, and do some nice things with it.
So, my question is: how can I tell a View that it is Not supposed to show things in a table, or a grid, or in teasers or whatever, but that it is supposed to hand its result, preferably an array, to my PHP code in the node.
I know I can do PHP in tpl files, but that's not an option. It really really Has to be done in that particular node, and that same node needs its input from a View. Question: how ?

modul’s picture

OK, found it :-)

I have a view called "my_test_view", and this view has a display called "nidlist".
This display lists the nid, and the writer of certain articles.
In a PHP enabled node, I insert this code:


// this simply calls the view, without showing anything
$view = views_get_view('my_test_view');

// this line prints the complete view (assuming you set the 
// 'items to display' to 0 in Views)
print $view->execute_display('nidlist');

// and here's the nice part
// $view = views_get_view('test_met_array');
$view->set_display('nidlist');
$view->pre_execute();
$view->execute();

if (!empty($view->result)) {
  $text = '';
  foreach ($view->result as $row => $values) {
    $text .=  $view->render_field('nid', $row) . "<br>";
    $text .= "The writer: " . $view->render_field('field_writer_value', $row) . "<br>";
    // or whatever beautiful tricks you want to play on the 
    // respective fields of your result
    // Notice that simply writing "render_field('writer' " etc. 
    // does not work. You have to add FIELD_writer_VALUE to it.
  }
  echo $text;
}
// let's free some memory: views can be biiiig
$view->destroy();

More information: http://drupal.org/node/1138866
It was a nice day.

shura80’s picture

Glad you find a solution, even if to it seems you have find a way that Views already implements by itself.

You have used a collection of data given by Views to embed the result in a node (which often, when you don't use fields, it's the smallest part a View is made of :D ).

Sounds a bit freaky to me, but at least it works ;)