Flex input and output in PHP
I want to print input value to flex in PHP.
My Flex Code ...
<mx:HTTPService id="sendReq" result="google(event)" showBusyCursor="true" method="POST" url="http://localhost/search/index.php" useProxy="false">
<mx:request xmlns="">
<keyword>
{keyword.text}
</keyword>
</mx:request>
</mx:HTTPService>
<mx:TextInput text="" id="keyword" left="130.5" top="89" right="228.5" height="40" fontSize="20" fontWeight="bold" borderStyle="outset" focusThickness="0"/>
<mx:Button click="sendReq.send();" id="search" label="search" right="133.5" top="91" height="40" width="75" alpha="1.0" fillAlphas="[1.0, 1.0]"/>
My PHP code,
$keyword = $_POST['keyword'];
echo $keyword;
But I cannot get the keyword from Flex. Can anyone find an error here that I cannot get.
a source to share
I don't have time to solve this problem, but here are some tips for debugging it:
First, I would trace everything in the opening tag for your HTTPRequest.
<mx:HTTPService id = "sendReq"
result = "trace( event )"
fault = "trace( event )"
showBusyCursor = "true"
method = "POST"
url = "http://localhost/search/index.php"
useProxy = "false">
If something is wrong with your request, you have absolutely no way of knowing that your request does not have an error handler!
On the PHP side, the best way to debug an application like this is with some kind of logging system.
Here's a pretty general logging function:
define( 'PATH_TO_LOG_FOLDER', "../Logs" );
public function log( $message ){
$logFileName = "log";
if(!$fp = @fopen(PATH_TO_LOG_FOLDER. DIRECTORY_SEPARATOR .
$logFileName .date('Y-m-d').".log", 'a+')){
return FALSE;
}
flock( $fp, LOCK_EX );
fwrite( $fp, $message );
flock( $fp, LOCK_UN );
fclose( $fp );
}
On http: //localhost/search/index.php call
$message = "";
for( $_REQUEST as $key => $val )
{
$message .= "$key = $val\n";
}
log( $message );
a source to share
In the past, when I used httpservice, I didn't set the method parameter (default is "get")
So, I used something like
<mx:HTTPService id="myCall"
url="{'somephp.php'}"
result="resultHandler(event)"
fault="faultHandler(event)"
showBusyCursor="false"
resultFormat="e4x">
<mx:request>
<somethingToSend>post data inside here</somethingToSend>
<time>{new Date().getTime()}</time>
</mx:request>
</mx:HTTPService>
Then inside php I will have
$ someVarThatsjustComeThrough = $ _REQUEST ["somethingToSend"];
If all you responded using php, please repeat it in XML format. This will make your work easier on the flexible side.
Always insert the time, it stops IE from potentially caching the php call.
a source to share