3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1277 Views |
-
[SOLVED] How to display an array of data

16 October 2009 at 4:23pm Last edited: 19 October 2009 2:27pm
Hi,
I'm just getting my head around how silverstripe works and would appreciate any tips to help get past a bit of a roadblock.
I'm building a method that once it has obtained an XML product list from Amazon, creates an array of information to display on a product page.
One approach I'm looking at is creating a simple array including items such as:
$product['title']
$product['description']
etcI believe I could pass them in through Arraydata (http://doc.silverstripe.org/doku.php?id=arraydata). However, I am confused about one aspect, which is that there can be multiple authors.
Since the authors would need their own array, I don't know how to combine this with the other data.
Any tips on how to approach this much appreciated.
Don
-
Re: [SOLVED] How to display an array of data

16 October 2009 at 4:54pm
Trying to display the data, I can't get anything to appear.
The method includes the following code to assemble the data:
function getItem() {
...
$aItem['ReviewerLocation'] = $item->CustomerReviews->Review->{0}->Reviewer->Location;
$aItem['Review'] = $item->CustomerReviews->Review->{0}->Content;
$aItem['Summary'] = $item->CustomerReviews->Review->{0}->Summary;$itemData = new DataObjectSet();
foreach($aItem as $key => $data) {
$itemData->push(new ArrayData($data));
}
return $itemData;
}I'm stuck on how to access this in the template.
-
Re: [SOLVED] How to display an array of data

16 October 2009 at 5:54pm
ArrayData expects an array() that is key>valued so you will have uniform access in the control loop in the template.
Ch-ch-check it out:
public function GetItem() {
...
$itemData = new DataObjectSet();
foreach( $item->CustomerReviews->Review as $review ) {
$data = array (
'ReviewerLocation' => $review->Location,
'Review' => $review->Content,
'Summary' => $review->Summary
);
$itemData->push(new ArrayData($data));
}
return $itemData;
}and for the template, assuming the above is in your controller
DUDE!!! REVIEWS ARE IN!!!!!!!!!!!!!
<% control GetItem %>
Some hoser from $ReviewerLocation had this to say
$Summaryoh and the rest is: $Review
<% end_control %> -
Re: [SOLVED] How to display an array of data

18 October 2009 at 8:35pm Last edited: 19 October 2009 2:27pm
Thank you for the reply.
EDIT: I realised what I was doing wrong.
In the end I decided to create a global variable, $ItemXML, which was then accessed by smaller methods, which grabbed the necessary arrays of info from the XML as needed.
| 1277 Views | ||
|
Page:
1
|
Go to Top |


