0

I created a custom service with mymodule_services_resources and I'm calling a function to return some items. This function inside is calling a view with views_get_view. The problem is always return an empty array.

If tested the same code somewhere else it shows the right results, but it does not work with services. I have something like this:

$view = views_get_view('the_view');
$view->set_display('default');
$args = array("my_param");
$view->set_arguments($args);
$view->pre_execute();
$view->execute();   
$view->result; //empty array in the WS  

I tried loading the admin user ($user = user_load(1); ) before calling the view but I had the same results.

Is there something I should add, change or remove in order I can get the results of a view calling service endpoint?

Thanks!

  • 1
    Try views_get_view_results('the_view', 'default', 'my_param'); instead, or use the Views datasource's sub module called Views JSON. – tyler.frankenstein Nov 19 '15 at 4:04
0

the module services_views will help you expose the view as a resource in two different ways

It has currently two features:

  • Create view based resource creating Services display in a view
  • Execute any view of the system via views resource call

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.