Is there a good way to get at the query or query object programmatically?

Events happening in the community are now at Drupal community events on www.drupal.org.
robertdouglass's picture

I want to get my hands on the query that gets called to generate a view. Possible after calling views_get_view?

Comments

Instead of using

karens's picture

Instead of using views_build_view('page', ...) and then views_pre_view() you could call views_build_view('result', ....) which stops before generating the view itself and returns an $info array that has the final query and a $result object you can use db_fetch_object() on.

Wicked!

robertdouglass's picture

Thanks Karen =)

Same code?

doublejosh's picture

Could I get some same code?

I've done this and it's still not working?

<?php
$view_name
= 'available'; //name of view
$view_args= array();
$view= views_get_view($view_name);
$view_object= views_build_view('result', $view, $view_args, FALSE);
$skills= db_fetch_object($view_object['query'])
print_r($skills);
?>

Sorry, the $query object is

merlinofchaos's picture

Sorry, the $query object is destroyed by the time views_build_view() returns. You won't be able to retrieve it from the outside.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: