Using Webservices I receive a reply in the following format:
Array
(
[Data] => Array
(
[A] => Array
(
[B] => Array
(
[0] => Array
(
[C] => Array
(
[value] => some value1
)
[D] => Array
(
[value] => some value2
)
[E] => some value3
)
[1] => Array
(
[C] => Array
(
[value] => some value4
)
[D] => Array
(
[value] => some value5
)
[E] => 5
)
)
[value] =>
using magento as php framework i create a controller displaying the following information
public function bynumberAction(){
$t = new \RocketShipIt\Track('fedex');
$response = $t->track('770190256519');
// parse results
$events['C'] = $response['A']['B']['C'];
$events['D'] = $response['A']['B']['D']
$events['E'] = $response['A']['B']['E']
// serve results
$this->loadLayout( array('default','shipping_track_bynumber'));
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('track_bynumber')
->setCollection($events)
->setTemplate('shipping/track/bynumber.phtml');
$this->renderLayout();
}
On the frontend phtml (bynumber.phtml) file I put:
<?php $res = $this->getCollection() ?>
<?php foreach ($res as $row) {echo $row['C'] . ' ' . $row['D'] . ' ' . $row['E'] . '<br />';} ?>
No information is displayed.. any help appreciated. brgds
There are more issues. First of all, there is a syntax error - missing semicolon after a command on lines 6 and 7 of function bynumberAction
.
Second: why do you have different array structure in your controller, if you know how the response looks?
You use: $response['A']['B']['C'];
Response looks: $response['Data']['A']['B']['0']['C'];
Try this in your controller:
$events = array()
foreach ($response['Data']['A']['B'] as $data)
{
$events[] = $data;
}
...and in a template:
foreach ($res as $row) { echo $row['C']['value'] ... }
At first sight you missed a depth there:
Instead of $events['C'] = $response['A']['B']['C'];
you should have $events['C'] = $response['A']['B'][0]['C'];
or $events['C'] = $response['A']['B'][1]['C'];
or make a loop, depends what you want.