3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1308 Views |
-
same dataobject on multiple pages

6 January 2010 at 8:26am Last edited: 6 January 2010 8:28am
Hello,
I am updating website for a festival, and I want to use page ProgramDay.php to store several concerts Concert.php as Dataobject.
It is obvious that ProgramDay 1 has different concerts than ProgramDay 2
My problem is that same concerts appear on EACH ProgramDay page, when I add concerts to ProgramDay 1, they appear also on Program Day 2..
Website is built with SS 2.2.2
Please help? Thanks in advance
Concert.php
<?php
class Concert extends DataObject {
static $db = array (
'Title' => 'Text',
'Place' => 'Text',
);
static $has_one = array (
'ProgramDay' => 'ProgramDay'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Title', 'Concert title' ) );
$fields->push( new TextField( 'Place' ) );
return $fields;
}}
?>ProgramDay.php
<?php
class ProgramDay extends Page {
static $has_many = array (
'Concerts' => 'Concert'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$tablefield = new ComplexTableField(
$this, 'Concerts', 'Concert',
array( 'Title' => 'Title', 'Place' => 'Place'), 'getCMSFields_forPopup' );
$tablefield->setParentClass('ProgramDay');$fields->addFieldToTab( 'Root.Content.Concerts', $tablefield );
return $fields;
}}
class ProgramDay_Controller extends Page_Controller {
function Siblings() {
$whereStatement = "ParentID = ".$this->ParentID;
return DataObject::get("Page", $whereStatement);
}}
?>
-
Re: same dataobject on multiple pages

6 January 2010 at 1:02pm Last edited: 6 January 2010 2:23pm
Hi janulka,
Seems like the forum is picking up again after the Christmas break.
Right, your problem is an interesting one and one i have had a few times and wanted to get past. But i haven't had a good excuse until now. After doing some digging in the source i have found out how to fix this problem (in theory
).
ProgramDay.php:
<?php
class ProgramDay extends Page {
static $has_many = array (
'Concerts' => 'Concert'
);function getCMSFields() {
$fields = parent::getCMSFields();$tablefield = new ComplexTableField(
$this, 'Concerts', 'Concert',
array( 'Title' => 'Title', 'Place' => 'Place'), 'getCMSFields_forPopup' );
$tablefield->setParentClass('ProgramDay');
$concerts = DataObject::get('Concert','ProgramDayID = ' . $this->ID);
$tablefield->setCustomSourceItems($concerts);$fields->addFieldToTab( 'Root.Content.Concerts', $tablefield );
return $fields;
}}
class ProgramDay_Controller extends Page_Controller {
function Siblings() {
$whereStatement = "ParentID = ".$this->ParentID;
return DataObject::get("Page", $whereStatement);
}}
Simply, what it does is fetches our own DOS that we want to have shown in the complextablefield and pushes it in. So i have chosen to show only the objects that belong to the current page.Hope that is what you were looking for.
-
Re: same dataobject on multiple pages

7 January 2010 at 7:55am
Hello,
Thanks a lot for fast reply.
This did not do it, unfortunately, still same problem..
-
Re: same dataobject on multiple pages

24 January 2010 at 9:42am
Have you checked the Database to make sure the Concert has the correct ProgramDayID attached?
If it does make sure your Concert getter in ProgramDay_Controller is forming the query correctly
public function getConcerts(){
return DataObject::get("Concert","ProgramDayID =".$this->ID);
}Then in your template just call <% control getConcerts %>
-
Re: same dataobject on multiple pages

24 January 2010 at 11:57pm
Thanks for reply!
I gave up on this one, and upgraded SS on the site to 2.3.4. and installed DataObjectManager, since then everything is alright. I never understood why this was happening..
| 1308 Views | ||
|
Page:
1
|
Go to Top |



