PDA

View Full Version : AMFPHP Error: Invalid argument supplied for foreach() line 255


MicahM
06-04-2004, 03:20 PM
I am at a loss what the problem is here. Code snippets and error below:

NetDebugger:
MethodName: "News.PostArticle"
Parameters (object #2)
.....[0]: "Name"
.....[1]: "Pass"
.....[2]: "Site"
.....[3]: "All"
.....[4]: "Test"
.....[5]: "Test article."
Status (object #2)
.....code: 2
.....description: "Invalid argument supplied for foreach()"
.....details: "C:\www\wwwroot\flashservices\io\AMFSerializer.php"
.....level: "Warning"
.....line: 225
PHP Code:"PostArticle" => array
( "description" => "Post a new article on the site.",
"access" => "remote",
"arguments" => array
( array("name" => "username", "required" => true, "type" => "string"), //userID for posting news
array("name" => "password", "required" => true, "type" => "string"), //password for userID ^
array("name" => "category", "required" => true, "type" => "string"), //category post will be listed under
array("name" => "server", "required" => true, "type" => "string"), //server news is for
array("name" => "headline", "required" => true, "type" => "string"), //headline for news
array("name" => "article", "required" => true, "type" => "string") //actual article
),
"returns" => "NewsID"
)
function PostArticle($username, $password, $category, $server, $headline, $article)
{ //post a new article on the site
$NewsID = 0;
return $NewsID;
}Flash Code:on(click)
{ #include "NetServices.as"
#include "Globals.as"
#include "NetDebug.as"

var mainResponder = new Object();
mainResponder.PostArticle_Result = function()
{ //
}

NetServices.setDefaultGatewayUrl(GatewayURL);
connection = NetServices.createGatewayConnection();
service = connection.getService("News",mainResponder);
service.PostArticle
( _parent.ti_username.text,
_parent.ti_password.text,
_parent.cb_categories.selectedItem.label,
_parent.cb_servers.selectedItem.label,
_parent.ti_headline.text,
_parent.ta_article.text
);
}

MicahM
06-04-2004, 04:48 PM
Okay, after much debugging and commenting out massive amounts of code I found my problem.

In the service, I had PostArticle setup to return an object. But in the PostArticle function I was only returning an integer. Two ways to fix this are:
to change the return line to read"return" => "integer" or change the function code to read$NewsID->blah = 123;
$NewsID->bleh = 456;