0

このメッセージの下部に配列を生成しています。私はCodeIgniterとこの配列を使用して、次のビューを介して階層情報を表示しています。

<?php foreach($products['top_cats'] as $top_cat): // $top_cat ?>
    <h2><?php echo $top_cat['cat_name']; ?></h2>
    <?php if( ! empty($products['sub_cats'][$top_cat['cat_id']])): ?>
        <?php foreach($products['sub_cats'][$top_cat['cat_id']] as $sub_cat): ?>
            <h3><?php echo $sub_cat['name']; ?></h3>
            <!-- problem below -->
            <?php $this->load->view('products_table_v', $products[$sub_cat['id']][$n]); ?>
            <?php var_dump($n); ?>
        <?php endforeach; ?>
    <?php endif; ?>
<?php endforeach; ?>

$products[top_cats][14]に関連し$products[sub_cats][14]、に$products[sub_cats][14]関連し$products[products][14]ます(これが理にかなっていることを願っています)。$products[products][14]ですから、私がforeachにいるときは、ビューに渡す必要があります$products[sub_cats][14](繰り返しますが、これが理にかなっていることを願っていますか?)...

私の問題は、正しいsub-sub(-sub)配列をサブビュー(適切に機能するforeachループが含まれている)に渡す必要があることです。配列にサブビューを与える方法について頭を悩ませることはできません(コードブラインドになりました)。

助けてください。

Array
(
    [top_cats] =&gt; Array
        (
            [14] =&gt; Array
                (
                    [cat_id] =&gt; 14
                    [cat_name] =&gt; Alcopops
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [2] =&gt; Array
                (
                    [cat_id] =&gt; 2
                    [cat_name] =&gt; Beers and Lagers
                    [cat_desc] =&gt; <p>hh</p>
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 0
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [79] =&gt; Array
                (
                    [cat_id] =&gt; 79
                    [cat_name] =&gt; Household
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [5] =&gt; Array
                (
                    [cat_id] =&gt; 5
                    [cat_name] =&gt; Soft Drinks
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [4] =&gt; Array
                (
                    [cat_id] =&gt; 4
                    [cat_name] =&gt; Spirits
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [3] =&gt; Array
                (
                    [cat_id] =&gt; 3
                    [cat_name] =&gt; Wines
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

        )

    [sub_cats] =&gt; Array
        (
            [3] =&gt; Array
                (
                    [25] =&gt; Array
                        (
                            [id] =&gt; 25
                            [name] =&gt; Champagne and Sparkling Wines
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 3
                        )

                    [22] =&gt; Array
                        (
                            [id] =&gt; 22
                            [name] =&gt; Australian Wines
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 3
                        )


                )

            [14] =&gt; Array
                (
                    [30] =&gt; Array
                        (
                            [id] =&gt; 30
                            [name] =&gt; White Rum
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 4
                        )

                    [32] =&gt; Array
                        (
                            [id] =&gt; 32
                            [name] =&gt; Liquers
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 4
                        )

                )

            [2] =&gt; Array
                (
                    [8] =&gt; Array
                        (
                            [id] =&gt; 8
                            [name] =&gt; Canned Lager
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [12] =&gt; Array
                        (
                            [id] =&gt; 12
                            [name] =&gt; Bottled Beer
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [10] =&gt; Array
                        (
                            [id] =&gt; 10
                            [name] =&gt; Bitter Cans
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [7] =&gt; Array
                        (
                            [id] =&gt; 7
                            [name] =&gt; Super Beers
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [13] =&gt; Array
                        (
                            [id] =&gt; 13
                            [name] =&gt; Cider
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [9] =&gt; Array
                        (
                            [id] =&gt; 9
                            [name] =&gt; Stout
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                )

            [] =&gt; Array
                (
                    [5] =&gt; Array
                        (
                            [id] =&gt; 5
                            [name] =&gt; Soft Drinks
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                    [79] =&gt; Array
                        (
                            [id] =&gt; 79
                            [name] =&gt; Household
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                    [14] =&gt; Array
                        (
                            [id] =&gt; 14
                            [name] =&gt; Alcopops
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                )

        )

    [products] =&gt; Array
        (
            [25] =&gt; Array
                (
                    [1347] =&gt; Array
                        (
                            [product_id] =&gt; 1347
                            [category_id] =&gt; 25
                            [name] =&gt; Asti Spumante Martini
                            [description] =&gt; 
                            [source_price] =&gt; 29.00
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 75.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 7.00
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 22.59
                            [product_code] =&gt; WNAS001
                            [product_image] =&gt; 1347_.jpg
                            [current_stock] =&gt; 5
                            [stock_level_id] =&gt; 0
                            [featured] =&gt; y
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 0
                            [discount_amount] =&gt; 3.50
                            [created_at] =&gt; 2009-07-22 10:21:57
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 25
                            [cat_name] =&gt; Champagne and Sparkling Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )

                    [1566] =&gt; Array
                        (
                            [product_id] =&gt; 1566
                            [category_id] =&gt; 25
                            [name] =&gt; Blossom Hill Zinfandel Sparkling
                            [description] =&gt; 
                            [source_price] =&gt; 29.99
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 70.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 8.49
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 29.35
                            [product_code] =&gt; WNBH010
                            [product_image] =&gt; 
                            [current_stock] =&gt; 30
                            [stock_level_id] =&gt; 
                            [featured] =&gt; n
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 
                            [discount_amount] =&gt; 0.00
                            [created_at] =&gt; 2011-03-21 10:35:47
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 25
                            [cat_name] =&gt; Champagne and Sparkling Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )


                )

            [22] =&gt; Array
                (
                    [1020] =&gt; Array
                        (
                            [product_id] =&gt; 1020
                            [category_id] =&gt; 22
                            [name] =&gt; Auction House Cabernet Sauvignon Merlot (Aus)
                            [description] =&gt; 
                            [source_price] =&gt; 20.00
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 75.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 5.00
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 27.18
                            [product_code] =&gt; WNAH008
                            [product_image] =&gt; 1020_.jpg
                            [current_stock] =&gt; 35
                            [stock_level_id] =&gt; 0
                            [featured] =&gt; y
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 0
                            [discount_amount] =&gt; 0.75
                            [created_at] =&gt; 2008-03-10 14:56:16
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 22
                            [cat_name] =&gt; Australian Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )

                )

        )

)
4

1 に答える 1

1
foreach($products['top_cats'] as $top_cat): // $top_cat ?>
    <h2><?php echo $top_cat['cat_name']; ?></h2>
    <?php if( ! empty($products['sub_cats'][$top_cat['cat_id']])): ?>
        <?php foreach($products['sub_cats'][$top_cat['cat_id']] as $sub_cat): ?>
            <h3><?php echo $sub_cat['name']; ?></h3>

            // Replaced bit
            <?php if( ! empty($products['products'][$sub_cat['id']])): ?>
                <?php $this->load->view('products_table_v', $products['products'][$sub_cat['id']]); ?>
            <?php endif; ?>

        <?php endforeach; ?>
    <?php endif; ?>
<?php endforeach; ?>
于 2012-05-08T22:11:24.743 に答える