2011-08-01 3 views
0

私のFlexサービスコールはNULLを返しています。Flex PHPサービスでパラメータint []を指定するにはどうすればいいですか

データベース:

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

event.resultがArrayCollectionのない場合は、1にキャストしようとしていることがちょうどヌル割り当てにつながります。 acUserをArrayのインスタンスにして、event.resultをそのインスタンスにキャストしてみてください。

+0

acUser = event.result as Array; //エラーArray型の値を関連のない型mx.collections:ArrayCollectionに暗黙的に変換します。ごめんなさい、これは助けになりませんでした。私の受け入れが低い理由は、多くの答えが実際に働くわけではないということです。 – user611468

+0

@ user611468私はそれがうまくいかない答えだとは思わない。私はacUserをArrayのインスタンスにするように言った。あなたは指示を読まなかったので、ソリューションが簡単に投稿できる価値がない初心者のエラーが現れました。実際にevent.resultにオブジェクトがあることを確認しましたか? –

関連する問題