Как открыть и отобразить значения массива в представлении CakePHP 3 из AWS-SDK - PullRequest
0 голосов
/ 09 сентября 2018

Я получаю данные из AWS DynamoDB, используя AWS SDK, все работает нормально, так как я получаю данные в Controller и могу отлаживать их.

Вот мой контроллер (без параметров и строк подключения):

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

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

Вот результат отладки:

[
    'Items' => [
        (int) 0 => [
            'email' => [
                'S' => 'whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI833053'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 1 => [
            'email' => [
                'S' => 'whatever@saunalahti.fi'
            ],
            'id' => [
                'S' => 'FI817755'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 2 => [
            'email' => [
                'S' => 'whateverm@gmail.com'
            ],
            'id' => [
                'S' => 'FI584457'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 3 => [
            'email' => [
                'S' => 'whatever@hotmail.com'
            ],
            'id' => [
                'S' => 'FI983129'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 4 => [
            'email' => [
                'S' => 'whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI156537'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 5 => [
            'email' => [
                'S' => 'whatever@lwhatever.fi'
            ],
            'id' => [
                'S' => 'FI626525'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 6 => [
            'email' => [
                'S' => 'whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI085033'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 7 => [
            'email' => [
                'S' => 'whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI099638'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 8 => [
            'email' => [
                'S' => 'vwhatever@hotmail.com'
            ],
            'id' => [
                'S' => 'FI543841'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 9 => [
            'email' => [
                'S' => 'j.whatever@hotmail.com'
            ],
            'id' => [
                'S' => 'FI155684'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 10 => [
            'email' => [
                'S' => 'whatever.whatever.whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI056429'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 11 => [
            'email' => [
                'S' => 'whatever.whatever@gmail.com'
            ],
            'id' => [
                'S' => 'FI010893'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 12 => [
            'email' => [
                'S' => 'whatever@kolumbus.fi'
            ],
            'id' => [
                'S' => 'FI344380'
            ],
            'driver' => [
                'M' => [
                    'city' => [
                        'S' => 'Vantaa'
                    ]
                ]
            ]
        ],
        (int) 13 => [
            'email' => [
                'S' => 'whatever@hotmail.com'
            ],
            '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?

Спасибо

1 Ответ

0 голосов
/ 09 сентября 2018

Я нашел ответ сам, немного изучив массив, нужно учитывать String как тип переменной:

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

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

}?>
...