I am working on a module to collect the results from several views, to be concatenated and then displayed. The views are returning JSON data using the views_datasource module.
To do this, I tried to set a variable to be the output of a view like so:
$my_view = views_get_view('drupalgap_content'); $my_view->set_display('getlatestdigest'); $output = $my_view->render();
Then I could concatenate the $output to another views output etc.
The problem lies in the fact that as soon as I call
$view->render() it renders the view results to the screen (I presume with a print() function) somewhere deep in the views core module.
After a ton of googling, I found that in the past,
$view->render() used to return a value, and this method was correct. However, somewhere along the line, they changed it so
$view->render() it renders the view results to the screen, making it impossible to concatenate the view output to another view output.
Other options I've looked into that don’t work:
$view_result = views_get_view_result('drupalgap_content','getlatestdigest');
This gets the view result, but it does not get the rendered JSON output that I need from the views_datasource module. So, it’s no good.
$view-execute(),$view->preview('getlatestdigest'); $view->execute_display('getlatestdigest', array());
All of these three functions do the same thing as view->render(), i.e. they output the nicely formatted results I want to the screen instead of assigning them to a variable.
does the same thing as view->render(), i.e. outputs the nicely formatted results I want to the screen instead of assigning them to a variable.
I should also mention that I am calling this module’s function using an AJAX call from a mobile app to the menu_hook for this page_callback. So I can not have it outputting anything to the “screen” until it is ready since AJAX will return the data to the client as soon as the output to the screen is called.