Hi there,
On my Page.ss template I am trying to access information on my contact page and have the loop run twice (2). The loop works in that it displays they information however it shows more than 2 results.
Any help would be great.
Snippet from Page.ss
================
<% control Page(Contact) %>
<% control Offices(2) %>
<ul>
<li>$City</li>
<li>$EmailAddress</li>
<li>$Phone</li>
</ul>
<% end_control %>
<% end_control %>
ContactPage.php
================
<?php
/**
* Defines the ContactPage page type
*/
class ContactPage extends Page {
static $db = array(
);
static $has_one = array(
);
static $has_many = array(
"Offices" => "Office"
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$Offices = new DataObjectManager(
$this,
'Offices',
'Office',
Office::$fields,
'getCMSFields_forPopup',
"`PageID` = $this->ID"
);
$fields->addFieldToTab('Root.Content.Offices', $Offices);
return $fields;
}
}
class ContactPage_Controller extends Page_Controller {
}
?>
Office.php
================
<?php
class Office extends DataObject {
static $db = array(
'Level' => 'Text',
'StreetAddress' => 'Text',
'POBox' => 'Text',
'City' => 'Text',
'Country' => 'Text',
'Phone' => 'Text',
'EmailAddress' => 'Text',
'GoogleMap' => 'HTMLText',
);
static $has_one = array(
'Page' => 'ContactPage',
'OfficeMapImage' => 'CustomImage',
);
static $fields = array(
'Level' => 'Level',
'StreetAddress' => 'StreetAddress',
'POBox' => 'POBox',
'City' => 'City',
'Country' => 'Country',
'Phone' => 'Phone',
'EmailAddress' => 'EmailAddress',
'GoogleMap' => 'GoogleMap',
);
public function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Level', 'Building floor level (optional)'));
$fields->push(new TextField('StreetAddress','Street address'));
$fields->push(new TextField('POBox', 'PO Box or private bag number'));
$fields->push(new TextField('City'));
$fields->push(new TextField('Country'));
$fields->push(new TextField('Phone'));
$fields->push(new TextField('EmailAddress','Email address'));
$fields->push(new TextField('GoogleMap', 'Paste the Google map code below - use www.bit.ly so the code is short and validates'));
$fields->push(new ImageField('OfficeMapImage', 'Location Map Image'));
return $fields;
}
}
?>