I just need to echo a field from a view. (This should be simple?)

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
freeMode's picture

Hello from a desperate noob. I put this off to the last minute because I assumed it would be easy, but now it seems that either a.) what I want to do is impossible or b.) it's so easy there aren't any discussions about it.

I am using using Drupal 6 to store information for a Flash site. The site is not really a Drupal site; I'm just using Drupal to manage the database that feeds information to it.

I am using Drupal Services with great success to get Views data into the site's Flash portion. (Attached code is the ActionScript that works in Flash.)

var gateway:String = "the/url/where/Drupal/Services/is";

var drupalServices:NetConnection = new NetConnection();

var connectResponder:Responder = new Responder(onSuccess, onError);

drupalServices.objectEncoding = ObjectEncoding.AMF3;

drupalServices.connect(gateway);

drupalServices.call("views.get", connectResponder, "the_view_i_want");

This code returns the view I want as an array that I can work with. Awesome. Now, I want to exactly the same thing with PHP. No login, no writing nodes, no authentication; I simply want to read data using "views.get()" and echo it.

Is that possible?

The desperate noob appreciate any assistance.

Comments

Hey freeMode, If you are

gbernier's picture

Hey freeMode,

If you are looking for straight up PHP then you'll have to use XMLRPC, at least that's what I'd recommend as it's out of the box and most PHP installs support it. If you are just looking to get the info to your Web Page then you could also use the JSON server to make the calls to get the data. If you go the JSON route then you can just use jQuery's AJAX calls.

Here's a example I have of doing it with JSON and Javascript

function loadProducts(selectedTid){
var url = "http://

<?php
print $_SERVER["HTTP_HOST"]
?>
/services/json";
$("#productListingLoad").html('<center><img src="/sites/all/themes/theme_name/graphics/ajax-loader.gif" /></center>');

$.ajax({
    type: "POST",
    url: url,
    dataType: "json",                   
    data: {method: '"service.service_name"', tids: '"' + selectedTid + '"'},
    success: populateProducts,
});

}

function populateProducts(response){
if(!response['#error']){
$("#productListingLoad").html(response['#data']);
}

}

I already have XMLRPC

freeMode's picture

Thanks for a speedy reply!

I already have XMLRPC installed and running. (Like you say, it's out of the box.) Can I make a call on it with a code snippet like that?

Hey freeMode, Here's a quick

gbernier's picture

Hey freeMode,

Here's a quick example, http://awebfactory.com.ar/node/297, I haven't used XMLRPC yet just JSON and AMFPHP. Hope this helps but when authentication isn't involved the calls are really simple

In that example, he's calling

freeMode's picture

In that example, he's calling services from another Drupal site. I want to call from a site that is NOT a Drupal site.

I know that is possible because I can do it in Flash. If Flash can call Services functions from an arbitrary URL, then it seems like you should be able to to do the same thing with PHP. But all the examples I've been able to find (including that one) only work if you are calling from a Drupal site.

Maybe I could take my page and turn it into a Drupal node. Then the whole thing would be in Drupal and I could just use the hooks...

Here's example code I posted

bsenftner's picture

Here's example code I posted showing how a remote non-Drupal site can communicate with a Drupal REST Service (implemented in the new Services 3.0):

http://drupal.org/node/1070066

Just like the Services' XMLRPC Server, its REST Server is also 'out of the box' with pre-built resources for comments, files, nodes, 'system', taxonomy, and users; enabling fairly useful remote operations with the Drupal installation after simply enabling Services. But no Views resource has been written and packaged with Services 3.0 yet. If you are comfortable writing the Drupal API PHP to get your View you're interested, writing a custom REST resource for communicating that to your Flash (or whatever) should be trivial.

and if you don't want to

bsenftner's picture

and if you don't want to bother with login/logout, simply don't enable any authentication and don't bother calling the login/logout routines in the code I posted.

Services

Group organizers

Group categories

Group notifications

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