質問

私のJaxpTreeオブジェクトに戻ります。ツリーはこのような関係を次のネストされたツリーにMySQLの関連テーブルのペアを変換することになっている


    /**
     * Generates a JaxpTree structure. Parameters are used by the recursive
     * function. Normally, they shouldn't be specified.
     *
     * @param   int     $parent_id
     * @param   string  $source_table
     * @param   bool    $include_childs
     *
     * @access  public
     * @return  JaxpTree
     * @since   1.0
     */
    function CreateTree(
        $parent_id = 0,
        $source_table = "_NodeTable",
        $include_childs = true
    )
    {
        # Copy field names to local variables for shortness.
        $pfId = $this->_ParentIdField;
        $fId  = $this->_IdField;
        $fL   = $this->_LabelField;

        # Determine source table. The iteration begins using NodeTable,
        # then, to fetch the items, uses ItemTable.
        $source_table = !$source_table ? "_NodeTable" : $source_table;

        # Get all rows from the source table.
        $rows = $this->{$source_table}->GetById($pfId, $parent_id, true);

        # If no rows, no process will be done.
        if ($rows)
        {
            # Iterate through the row list.
            foreach ($rows as $r)
            {
                # Get label and id values.
                $label = $r->Columns[$fL]->Value;
                $id = $r->Columns[$fId]->Value;

                # If this node has childrens...
                if ($this->{$source_table}->GetById($pfId, $id) && $include_childs)
                {
                    # Do recursive call using this node as root.
                    $array[$label] = $this->CreateTree($id);

                    # If this node has items...
                    if ($this->_ItemTable->GetById($pfId, $id))
                    {
                        # Do recursive call using this node as root
                        # scanning the item table.
                        $array[$label]->ItemList = $this->CreateItemList($id);
                    }
                }
                else # This node has no child, so there's no need for
                     # more nested trees.
                {
                    # Create a new TreeNode.
                    $new_node = new JaxpTreeNode($id);

                    # Send a JaxpMySqlRow object to the node.
                    # This will turn the row into node elements.
                    $new_node->LoadFromMySqlRow($r);

                    # Store the node.
                    $array[] = $new_node;
                    if ($source_table != "_ItemTable")
                    {
                        $array[$new_node->Attributes->Get($fL)->Value] = $new_node;
                    }

                    # If the node has items...
                    if ($this->_ItemTable->GetById($pfId, $id))
                    {
                        # Do recursive call using this TreeNode as root
                        # scanning the item table.
                        $new_node->ItemList = $this->CreateItemList($id);
                    }
                } # End checking for children.
            } # End iterating the row list.
        } # End checking for rows.

        # Return a JaxpTree object, using the array as contents.
        return (isset($array)
                ? new JaxpTree(
                        $array, null,
                        ($parent_id
                        ? $this->CreateTree($parent_id, "_NodeTable", false)
                        : null)
                  )
                : false);
    } // CreateTree()
私は(イタリックラインを参照)、追加の親を参照してオブジェクトを返すようにしようとすると、

、私は無限再帰ループに巻き込まとPHPがクラッシュします。

どこが間違ってここに行くのですか?

役に立ちましたか?

解決

$は、私が見遠くのように、それはあなたのコード内の任意の場所に変更されていないので、あなたは、常にあなたの最初の呼び出しで使用されていたものと同じになります再帰呼び出しで提供PARENT_ID。それでは、あなたの問題という、あなたは何度も何度も同じパラメータで同じ関数を呼び出すことにより、無限ループを作成します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top