如何在来自AWS-SDK的CakePHP 3视图中打开和回显数组值

问题描述 投票:0回答:1

我使用AWS SDK从AWS DynamoDB获取数据,一切正常,因为我在Controller中获取数据并且我可以调试它。

这是我的控制器(没有参数和连接字符串):

$result = $this->Aws->DynamoDB->scan($params);

$this->set('result', $result);

这是Debug结果:

[
    'Items' => [
        (int) 0 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI833053'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 1 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI817755'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 2 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI584457'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 3 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI983129'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 4 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI156537'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 5 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI626525'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 6 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI085033'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 7 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI099638'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 8 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI543841'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 9 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI155684'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 10 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI056429'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 11 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI010893'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 12 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI344380'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 13 => [
            'email' => [
                'S' => '[email protected]'
            ],
            'id' => [
                'S' => 'FI024009'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ]
    ],
    'Count' => (int) 14,
    'ScannedCount' => (int) 84,
    '@metadata' => [
        'statusCode' => (int) 200,
        'effectiveUri' => 'https://dynamodb.eu-west-1.amazonaws.com',
        'headers' => [
            'server' => 'Server',
            'date' => 'Sun, 09 Sep 2018 10:45:05 GMT',
            'content-type' => 'application/x-amz-json-1.0',
            'content-length' => '1491',
            'connection' => 'keep-alive',
            'x-amzn-requestid' => '6CJS11E3S5RK2CKI7L6DM0QBURVV4KQNSO5AEMVJF66Q9ASUAAJG',
            'x-amz-crc32' => '219838078'
        ],
        'transferStats' => [
            'http' => [
                (int) 0 => []
            ]
        ]
    ]
]

我有问题来回应结果集,我已经尝试了所有这些而没有运气:

foreach ($result['Items'] as $i) {
//$prod_drivers = $marshaler->unmarshalItem($i);

//echo implode($i);

//echo $i['email'];
//echo $i->email;

//    echo $prod_drivers['email']."<br/>";
}

如何在html中打开echo for echo?

谢谢,

php amazon-web-services attributes amazon-dynamodb cakephp-3.x
1个回答
0
投票

我自己找到了一个调查数组的答案,必须考虑String作为变量类型:

<php foreach ($result['Items'] as $row) { ?>

      <tr>
        <td>John</td>
        <td>Doe</td>
        <td><?php echo $row['email']['S']?></td>
      </tr>
<?php

}?>
© www.soinside.com 2019 - 2024. All rights reserved.