如何在Flex PHP服务中提供参数int []

时间:2011-08-01 08:20:42

标签: flex flex4

我的Flex服务电话正在返回Null可以告诉我哪里出错了吗?

数据库:

user_id: 1 
user_name: stephen
user_password: qwerty
status: Active

user_id: 2 
user_name: john
user_password: qwerty
status: Passive

user_id: 3 
user_name: marice
user_password: qwerty
status: Awaiting

user_id: 4
user_name: maria
user_password: qwerty
status: Passive

PHP服务方法:

public function getAllUserByStatus($arrStatus) {

    $rows = array();

    foreach ($arrStatus as $item)
    {
        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE status=?");     
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 's', $item);      
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);
        $this->throwExceptionOnError();

        mysqli_stmt_bind_result($stmt, $row->user_id, $row->user_name, $row->user_password, $row->status);

        while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->user_id, $row->user_name, $row->user_password, $row->status);
        }

        mysqli_stmt_free_result($stmt);
    }

    mysqli_close($this->connection);
    return $rows;
}

PHP测试查询:

<?php 
    include('UserService.php'); 
    $o = new UserService(); 
?>

<pre>
<?php 
    var_dump($o->getAllUserByStatus(array('Active','Passive')));
?>
</pre>

PHP测试结果:

array
  0 => 
    object(stdClass)[4]
      public 'user_id' => int 1
      public 'user_name' => string 'stephen' (length=7)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Active' (length=6)
  1 => 
    object(stdClass)[5]
      public 'user_id' => int 2
      public 'user_name' => string 'john' (length=4)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Passive' (length=7)
  2 => 
    object(stdClass)[3]
      public 'user_id' => int 4
      public 'user_name' => string 'maria' (length=5)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Passive' (length=7)

Flex应用程序(返回Null,为什么):

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:userservice="services.userservice.*"
               minWidth="955" minHeight="600"     creationComplete="application1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            import mx.rpc.events.ResultEvent;

            protected var acUser:ArrayCollection;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                getAllUserByStatusResult.token = userService.getAllUserByStatus(new ArrayCollection(new Array(['Active','Passive'])));
                getAllUserByStatusResult.addEventListener(ResultEvent.RESULT, getAllUserByStatusResultHandler);
            }

            protected function getAllUserByStatusResultHandler(event:ResultEvent):void
            {
                acUser = event.result as ArrayCollection;

                // Break Point to examine acUser
        }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:CallResponder id="getAllUserByStatusResult"/>
        <userservice:UserService id="userService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:Application>

1 个答案:

答案 0 :(得分:1)

如果event.result不是ArrayCollection,那么尝试将其强制转换为一个将导致null赋值。尝试将acUser作为Array的实例并将event.result转换为该实例。