0

データベースからユーザー オブジェクトのコレクションを作成する関数があります。

public static function GetUsersByGroup($instanceID, $groupID)
{               
    $col = null;
    if($groupID != null) 
    {
        $col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_USERGROUP_MEMBERS,array ($instanceID, $groupID));
    }
    else
    {
        $col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_NOGROUP_MEMBERS,$instanceID);
    }
    echo "this is the collection I am going to return: <pre>";
    print_r($col);
    echo "</pre>";
    return $col;
}

メソッドの下部にデバッグ出力がありますが、ポイントは、そのメソッドを null groupid パラメータで呼び出す場合、つまり 2 番目の条件を実行すると、受け取ると予想されるコレクションの適切な表示が出力されることです。これは素晴らしいことです。

でも ..

これが私の呼び出し方法です:

             echo "<br> Collection passed through is: </br>";
             $collection =  UserGroup::GetUsersByGroup($this->GetInstance()->id,$grouplist->GetCurrentCommandParam());
             print_r($collection);
             $userlist->UpdateCollection($collection);
             $userlist->DeSelect();

興味深いのは、次の出力です。

  this is the collection I am going to return: 
Collection Object
(
    [_valueType:protected] => User
    [_isBasicType:protected] => 
    [_validateFunc:protected] => 
    [_collection:protected] => Array
        (
            [0] => User Object
                (
                    [valid] => 
                    [validationMessage] => 
                    [id] => 29
                    [table:private] => user
                    [fields:private] => Array
                        (
                            [title] => mrs
                            [fname] => Kirsty
                            [lname] => Howden
                            [email] => kirsty2@softyolk.com
                            [password] => xxxxxxxx
                            [lastlogin] => 2009-07-05 15:20:13
                            [instanceID] => 2
                            [deliveryAddress] => 
                            [invoiceAddress] => 
                            [tel] => 01752848484
                            [isAdmin] => 0
                            [disabled] => 0
                            [mustAuthorise] => 
                            [usergroupID] => 
                        )

                    [validationRules:private] => Array
                        (
                        )

                    [_profileStartTime:protected] => 
                    [_profileTag:protected] => 
                )

            [1] => User Object
                (
                    [valid] => 
                    [validationMessage] => 
                    [id] => 31
                    [table:private] => user
                    [fields:private] => Array
                        (
                            [title] => master
                            [fname] => Seb
                            [lname] => Howden
                            [email] => seb@antithug.co.uk
                            [password] => xxxxxxxxx
                            [lastlogin] => 2009-07-09 02:02:24
                            [instanceID] => 2
                            [deliveryAddress] => saltash
                            [invoiceAddress] => saltash
                            [tel] => 8908908
                            [isAdmin] => 0
                            [disabled] => 0
                            [mustAuthorise] => 
                            [usergroupID] => 
                        )

                    [validationRules:private] => Array
                        (
                        )

                    [_profileStartTime:protected] => 
                    [_profileTag:protected] => 
                )

        )

)

Collection passed through is: 
this is the collection I am going to return: 
Collection Object
(
    [_valueType:protected] => User
    [_isBasicType:protected] => 
    [_validateFunc:protected] => 
    [_collection:protected] => Array
        (
        )

)
Collection Object ( [_valueType:protected] => User [_isBasicType:protected] => [_validateFunc:protected] => [_collection:protected] => Array ( ) )

返されたオブジェクトは変更されていますか??

GetUsersByGroup メソッドが userGroupID で呼び出された場合、つまり最初のケースでは、出力はすべて期待どおりです。

メソッドから条件を削除して単純に返すと$col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_NOGROUP_MEMBERS,$instanceID);、すべての出力が期待どおりになります。

else 条件が正しく実行され、リターン時に破損しているように見えますが、これは、else 条件が存在し、else 条件を削除し、else 条件でメソッド呼び出しの結果を単に返す場合にのみ発生し、すべてが次のとおりです。期待される。

何かアイデアはありますか?

ありがとう

UserGroup::GetCollection メソッドを追加しました (これは深いうさぎの穴ですが、続けることができます)

protected static function GetCollection($class, $sqlID, $params = null)
{
    $dal = DAL::GetInstance(); //not to be confused with the Instance object, this is an instance of DAL        

    $collection = new Collection($class);
    $items = $dal->QueryForAssoc($sqlID,$params);

    foreach($items as $item)
    {
          $itemObject = new $class();
          $itemObject->LoadFromList($item);
          $collection->add($itemObject);
    }

    return $collection;        
}

さらに明確にするために、次の作業はうまくいきます::

public static function GetUsersByGroup($instanceID, $groupID)
{               
    $col = null;
    //if($groupID != null) 
    //{
        //$col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_USREGROUP_MEMBERS,array ($instanceID, $groupID));
    //}
    //else
    //{
        $col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_NOGROUP_MEMBERS,$instanceID);
   // } 
   return $col; 
}

行がelseブロックにある場合にのみ問題が発生します。

4

2 に答える 2

1

ここで問題になる可能性があるのは、UserGroup::GetCollection関数にあります。PHP 5 はすべてのオブジェクトを参照によって渡すため、これらのオブジェクトを取得する方法に基づいてこのルーチンで何らかの変更を行っている場合、この変更UserGroup::GetCollectionは終了後も保持されます。

これら 2 つの関数呼び出しの違いを注意深く調べて、 でオブジェクトの変更が発生していないことを確認しUserGroup::GetCollectionます。

$col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_USERGROUP_MEMBERS,array ($instanceID, $groupID));

対。

$col = UserGroup::GetCollection("User" ,_DB_GET_ALL_INSTANCE_NOGROUP_MEMBERS,$instanceID);
于 2009-08-07T17:10:25.637 に答える
0

メソッドが 2 回呼び出されていることが判明しました。2 回目の呼び出しは他の条件を使用しており、空のコレクションを返しています (問題の結果)。

各条件にエコーを設定すると、呼び出されたときに確認できます。最初に null ケースが呼び出され、次に非 null ケースが呼び出されます。

実際のエラーは、同じポストバックでメソッドを 2 回呼び出すステートフル リストがあったことです。捕まえにくい。

ご覧いただきありがとうございます

于 2009-08-07T20:31:48.630 に答える