I want to create a few views in Views and then access them in a separate module. Is there a way I can get at the SQL that a view creates? Also, is there any way I can get a list of views available on the site?

I've found http://drupal.org/node/99612 which lists some functions which I think might be useful, but I'm not entirely sure...

Comments

dawehner’s picture

you can get it using $view->build_info['query']

liquixis’s picture

jim0203’s picture

Thanks @dereine and @overall, that's great! This isn't really documented anywhere (as far as I can see) so as soon as I've worked out precisely how to get it to do what I want to do I'll write a noob's tutorial.

frdesign’s picture

I'm no php pro but with this little tutorial as a starting point I've been able to do cool things with views.
http://www.broadlatitude.com/blogs/matt/content/drupal-tip-never-query-c...

dawehner’s picture

@frdesign

i just see that you are missing $view->pre_execute() :)

frdesign’s picture

Ah, no wonder I was had a couple of issues controlling how many results to show (found a hack that worked). Thanks for the heads up dereine! I'll go back and update my code. :-)

dawehner’s picture

Status: Active » Fixed

so this is fixed

jim0203’s picture

I've written a tutorial on getting started with this sort of stuff at http://state68.com/node/2. It's designed to be useful for total Views noobs like me - hope it helps some people. Thanks again to all who helped me out.

Roi Danton’s picture

For a more detailed description than the tutorial posted in #8 provides see Get the result a view creates.

Status: Fixed » Closed (fixed)

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