Smarty 不显示 PHP 会话对象的数组元素


Smarty doesn't show array element of PHP session object

Code

{assign var=shipping_method value=$smarty.session.cart->sub_content}
{$shipping_method|print_r}
->{$shipping_method.products_name}<-

输出

Array
(
[customers_id] => 4
[products_name] => Abholung
[products_key] => shipping
[products_key_id] => 2
[products_model] => Abholung
[products_quantity] => 
[products_price] => 0
[products_tax_class] => 0
[products_discount] => 
[type] => shipping
[status] => 0
[sort_order] => 
[shop_id] => 
)
Array
-><-

第二个"阵列"有些奇怪。但是我如何调试它并访问我需要的数组元素呢?

谢谢。

我已经用foreach调试了数组并找到了解决方案。似乎所有数组元素都在子数组"shipping"下:

        {foreach key=key0 item=val0 from=$shipping_method}
        {$key0}/{$val0}
        {foreach key=key item=val from=$val0}
        {$key}/{$val}
        {if $key=='products_name'}
        {assign var=shipping_method_name value=$val}
        {/if}
        {/foreach}
        {/foreach}
        {$shipping_method_name}

将输出:

                    shipping/Array
                    customers_id/4
                    products_name/Abholung  
                    products_key/shipping
                    products_key_id/2
                    products_model/Abholung
                    products_quantity/
                    products_price/0
                    products_tax_class/0
                    products_discount/
                    type/shipping
                    status/0
                    sort_order/
                    shop_id/
                    Abholung

因此,要访问所需的值,我需要使用以下代码:

    {$shipping_method.shipping.products_name}

问题解决了,但是为什么 {$shipping_method|print_r} 没有显示"shipping"子数组。这是一个聪明的错误吗?