how to pass arguments to views.getview?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by vannen-gdo on September 9, 2008 at 3:09pm

Hello,

I've successfuly got flash as3 and Drupal talking, but I need to pass arguments to views.getview so that I can cut down on the amount of data transfered.

I'm using the following to connect, modified from the AMFPHP "hello world" example:

package {
import flash.net.NetConnection;
import flash.net.Responder;

import flash.net.URLRequest;

import flash.events.EventDispatcher;
import flash.events.Event;

public class ConnectToDrupal extends EventDispatcher{

private var gateway:String = "http:// mywebsitename /drupal/services/amfphp";
private var connection:NetConnection;
private var responder:Responder;

public function downLoad(viewName:String) {
// Responder to handle data returned from AMFPHP.
responder = new Responder(onResult, onFault);
connection = new NetConnection;
// Gateway.php url for NetConnection
connection.connect(gateway);
connection.call("views.getView", responder, viewName);
}



// Handle a successful AMF call.
public function onResult(result:Object) {
MenuGlobal.PAGES["temp"] = result;
// tell page to start populating itself
this.dispatchEvent(new Event(Event.COMPLETE));
}


// Handle an unsuccessfull AMF call.
public function onFault(fault:Object) {
// return fault;
}

}

}

Which, when I call the downLoad method, is connecting fine, and making available to Flash a result object containing the view in question. What I need to do is cut down the result object using an argument that I pass to views.getView.

Presumably I need to add the argument to:

connection.call("views.getView", responder, viewName);

but I've tried:

connection.call("views.getView", responder, viewName, arg);

with no success. How do I do this?!

DV

Comments

Calling views.getview and passing arguments

Posted by ajeancharles on September 10, 2008 at 12:14am

I used RemoteObject in Flex and was sucessful. Below is my commented code. Maybe you can adapt it

[Bindable]
public var pictures:Array ; // view loaded is a bunch of images
[Bindable]
public var all_view_arr:Array ;// list of views
[Bindable]
public var view_to_load:String ; // will use to pass name of view to load
public var views:RemoteObject ; // to load a specific view i.e. "views" service to call "views.getView"
public var allviews:RemoteObject ; // my own service to get all views, the name of service: "allviews"

public function init_allviews():void
{
allviews = new RemoteObject("amfphp") ;
allviews.source = "allviews" ;// my own drupal service
allviews.setRemoteCredentials("","") ;
allviews.addEventListener(ResultEvent.RESULT,onAllViewsResult) ;
allviews.addEventListener(FaultEvent.FAULT, onFault) ;
allviews.addEventListener(InvokeEvent.INVOKE, onInvoke) ;
}
public function init_views():void
{
view_to_load = "sspchillingout" ; // name of the view that I want to load
views = new RemoteObject("amfphp") ;
views.source = "views"; // the drupal views service name for loading views
views.addEventListener(ResultEvent.RESULT,onViewsResult) ;
views.addEventListener(FaultEvent.FAULT, onFault) ;
views.addEventListener(InvokeEvent.INVOKE, onInvoke) ;
}

public function init():void
{
// Alert.show("Calling init()", "Info") ;
init_views();
init_allviews();
getPictures() ;
getAllViews() ;
}

public function onViewsSelectionChanged(event:Event):void
{
//Alert.show(views_list_id.selectedItem.name,"Views Selection Changed to") ;
view_to_load = views_list_id.selectedItem.name ; // drop down combobox with other view names
}

public function onInvoke(event:InvokeEvent):void
{
//Alert.show("Invoking Remote Object", event.toString() ) ;
}

public function selectionChange(event:Event):void
{
pictID.source = dgID.selectedItem.images.preview ; // this is a Drupal Image
}

public function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString,"Error") ;
}

public function onViewsResult(event:ResultEvent):void
{
//Alert.show("Picture list loaded from Drupal", "Info") ;
pictures = ArrayUtil.toArray(event.result) ; // return data(images) from drupal

}

public function onAllViewsResult(event:ResultEvent):void
{
//Alert.show("All view gotten from Drupal", "Info") ;
all_view_arr = ArrayUtil.toArray(event.result) ; // list of all views returned from Drupal
}
public function getAllViews():void
{ allviews.view();}

// below I call "views.getView" Drupal Service and passing parameters
public function getPictures():void
{
// Alert.show("calling views.getView for "+ view_to_load, "Info") ;
views.getView(view_to_load, ['nid','title','images']); // view_to_load contains name of view to load
}

That helped! Simply, I'd not

Posted by vannen-gdo on September 16, 2008 at 12:38pm

That helped!

Simply, I'd not been passing the arguments in the correct format. Looking at your code:

views.getView(view_to_load, ['nid','title','images']); // view_to_load contains name of view to load

I then tried editing my code to read:

var arrayOfArgs:Array = new Array('title','images');

connection.call("views.getView", responder, viewName, arrayOfArgs)

Passing arguments speeds up the data transfer by an incredible amount. I've gone from 2-4 seconds to load my images into a flash movie on the web down to almost instantaneous.

Thanks, DV

No problem!

Posted by ajeancharles on September 16, 2008 at 11:52pm

I am glad that was helpful. I am still learning this stuff. I started at the begining of the year

a question please

Posted by serguitus on May 20, 2010 at 5:41am

what if I would want to pass an argument to the view that is inside of some other variable (i mean on something like dinamic_text.text). I ́ve tried many things but nothing works
thanks

Get View Name

Posted by willsmith308 on October 7, 2010 at 3:28pm

I have a problem where there are three exposed filters each for a particular content type ,I want to make into one exposed filter which searches for all content types, I have started with the view-exposed-form.tpl.php is it correct or what is the best way to do this

Services

Group organizers

Group categories

Group notifications

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

AltStyle によって変換されたページ (->オリジナル) /