我在这条消息的底部生成了数组。我正在使用 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 for 中时,我需要传递给视图$products[sub_cats][14]
(再次,我希望这是有道理的?)...
我的问题是我需要将正确的 sub-sub(-sub) 数组传递给子视图(其中包含一个良好的工作 foreach 循环)。我无法理解如何为数组提供子视图(我已经把代码弄瞎了)。
请帮忙。
Array
(
[top_cats] => Array
(
[14] => Array
(
[cat_id] => 14
[cat_name] => Alcopops
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] =>
[cat_sort_order] =>
[category_active] => y
)
[2] => Array
(
[cat_id] => 2
[cat_name] => Beers and Lagers
[cat_desc] => <p>hh</p>
[cat_featured] => n
[cat_parent_id] => 0
[cat_sort_order] =>
[category_active] => y
)
[79] => Array
(
[cat_id] => 79
[cat_name] => Household
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] =>
[cat_sort_order] =>
[category_active] => y
)
[5] => Array
(
[cat_id] => 5
[cat_name] => Soft Drinks
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] =>
[cat_sort_order] =>
[category_active] => y
)
[4] => Array
(
[cat_id] => 4
[cat_name] => Spirits
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] =>
[cat_sort_order] =>
[category_active] => y
)
[3] => Array
(
[cat_id] => 3
[cat_name] => Wines
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] =>
[cat_sort_order] =>
[category_active] => y
)
)
[sub_cats] => Array
(
[3] => Array
(
[25] => Array
(
[id] => 25
[name] => Champagne and Sparkling Wines
[desc] =>
[cat_parent_id] => 3
)
[22] => Array
(
[id] => 22
[name] => Australian Wines
[desc] =>
[cat_parent_id] => 3
)
)
[14] => Array
(
[30] => Array
(
[id] => 30
[name] => White Rum
[desc] =>
[cat_parent_id] => 4
)
[32] => Array
(
[id] => 32
[name] => Liquers
[desc] =>
[cat_parent_id] => 4
)
)
[2] => Array
(
[8] => Array
(
[id] => 8
[name] => Canned Lager
[desc] =>
[cat_parent_id] => 2
)
[12] => Array
(
[id] => 12
[name] => Bottled Beer
[desc] =>
[cat_parent_id] => 2
)
[10] => Array
(
[id] => 10
[name] => Bitter Cans
[desc] =>
[cat_parent_id] => 2
)
[7] => Array
(
[id] => 7
[name] => Super Beers
[desc] =>
[cat_parent_id] => 2
)
[13] => Array
(
[id] => 13
[name] => Cider
[desc] =>
[cat_parent_id] => 2
)
[9] => Array
(
[id] => 9
[name] => Stout
[desc] =>
[cat_parent_id] => 2
)
)
[] => Array
(
[5] => Array
(
[id] => 5
[name] => Soft Drinks
[desc] =>
[cat_parent_id] =>
)
[79] => Array
(
[id] => 79
[name] => Household
[desc] =>
[cat_parent_id] =>
)
[14] => Array
(
[id] => 14
[name] => Alcopops
[desc] =>
[cat_parent_id] =>
)
)
)
[products] => Array
(
[25] => Array
(
[1347] => Array
(
[product_id] => 1347
[category_id] => 25
[name] => Asti Spumante Martini
[description] =>
[source_price] => 29.00
[source_pack_size] => 6
[source_item_size] => 75.00
[source_unit_id] => 2
[resale_price] => 7.00
[resale_pack_size] => 1
[percentage_return] => 22.59
[product_code] => WNAS001
[product_image] => 1347_.jpg
[current_stock] => 5
[stock_level_id] => 0
[featured] => y
[active] => y
[so_member_of_group_id] => 0
[discount_amount] => 3.50
[created_at] => 2009-07-22 10:21:57
[modified_at] =>
[product_unit_id] => 2
[unit_name] => Centilitre
[unit_symbol] => cl
[stock_levels_id] =>
[stock_levels_name] =>
[cat_id] => 25
[cat_name] => Champagne and Sparkling Wines
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] => 3
[cat_sort_order] =>
[category_active] => y
)
[1566] => Array
(
[product_id] => 1566
[category_id] => 25
[name] => Blossom Hill Zinfandel Sparkling
[description] =>
[source_price] => 29.99
[source_pack_size] => 6
[source_item_size] => 70.00
[source_unit_id] => 2
[resale_price] => 8.49
[resale_pack_size] => 1
[percentage_return] => 29.35
[product_code] => WNBH010
[product_image] =>
[current_stock] => 30
[stock_level_id] =>
[featured] => n
[active] => y
[so_member_of_group_id] =>
[discount_amount] => 0.00
[created_at] => 2011-03-21 10:35:47
[modified_at] =>
[product_unit_id] => 2
[unit_name] => Centilitre
[unit_symbol] => cl
[stock_levels_id] =>
[stock_levels_name] =>
[cat_id] => 25
[cat_name] => Champagne and Sparkling Wines
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] => 3
[cat_sort_order] =>
[category_active] => y
)
)
[22] => Array
(
[1020] => Array
(
[product_id] => 1020
[category_id] => 22
[name] => Auction House Cabernet Sauvignon Merlot (Aus)
[description] =>
[source_price] => 20.00
[source_pack_size] => 6
[source_item_size] => 75.00
[source_unit_id] => 2
[resale_price] => 5.00
[resale_pack_size] => 1
[percentage_return] => 27.18
[product_code] => WNAH008
[product_image] => 1020_.jpg
[current_stock] => 35
[stock_level_id] => 0
[featured] => y
[active] => y
[so_member_of_group_id] => 0
[discount_amount] => 0.75
[created_at] => 2008-03-10 14:56:16
[modified_at] =>
[product_unit_id] => 2
[unit_name] => Centilitre
[unit_symbol] => cl
[stock_levels_id] =>
[stock_levels_name] =>
[cat_id] => 22
[cat_name] => Australian Wines
[cat_desc] =>
[cat_featured] => n
[cat_parent_id] => 3
[cat_sort_order] =>
[category_active] => y
)
)
)
)