Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

2.4 - DOM in SiteConfig not working for me


Reply


39 Posts   6750 Views

Avatar
Geo

Community Member, 1 Post

13 July 2010 at 9:13pm

hi, i made a form, and its working fine, but i wana make a link to the full event and cant get it working,dont know whats wrong. my code:

<div id="Content" class="typography">
<h2>Current event information:</h2>
<ul id="NewsList">
<% if Children %>
<% control EventResults %>
<li>
<div class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Event</a></div>
<div class="newsDateTitle">Your email address: $Email </div>
<div class="newsDateTitle">Where: $Area,$Country</div>
<div class="newsDateTitle">When: $Date </div>
<div class="newsSummary">What sector: $Sector</div>
<div class="newsSummary">Description: $Description.FirstSentence</div>
</li>
<br/>
<% end_control %>
<% end_if %>
</ul>
</div>

it makes the link but when you click it,it just goes to homepage, and doesnt display it. im new to silver stripe, and all the tut links is from cms where you putted it in, but this one from my db is giving me problems

Avatar
Carbon Crayon

Community Member, 598 Posts

17 July 2010 at 10:57pm

@UC - Did that work? Have you added it or does it need to be changed? Just wondering as it would be great not to have to make the changes for DOM in SiteConfig every time.

@Geo - This is because your DataObjects are not pages so they can't be displayed like that. I wrote a tutorial a while back on how to display DO on a page, but unfortunately it requires a little extra work to get going on 2.4. Still have a look through as it will give you a basic understanding of what is going on and I did leave a comment which points in the direction of making it work in 2.4.

I will be releasing a new Tut on doing this 'properly' in 2.4 when the NEW SSBits site launches soon ;)

Aram

www.ssbits.com - SilverStripe Tutorials, Tips and Other bits

Avatar
MarcusDalgren

Community Member, 288 Posts

18 July 2010 at 1:55am

I just wanted to chime in and say that setSourceID can be used in other contexts since it can be used to add a DOM to a page that's linked to something else. Not a very common usecase perhaps but I've used setSourceID like that a couple of times and it works great. The difference to Arams code is that in my version I give $sourceID precedence in the sourceID() function since I'm figuring that if I actually go and set it myself manually then it's a special case and I specfically want that behaviour.

So the difference in my version is that I check $this->sourceID first in the sourceID() function and return that if it's set, otherwise do the normal stuff.

Avatar
UncleCheese

Forum Moderator, 4094 Posts

18 July 2010 at 3:29am

Aram, that's all checked in. Thanks!

Avatar
klikhier

Community Member, 150 Posts

1 August 2010 at 3:35am

I found that the example from SSbits doesnot work for an ImageDOM? This is the code I use. What changes are required to make this work?

<?php
class CustomSiteConfig extends DataObjectDecorator{

function extraStatics() {
return array(
'db' => array(
),
'has_many' => array(
      'SlideshowPhotos' => 'SlideshowPhoto'
)
);
}

public function updateCMSFields(FieldSet &$fields) {

$idom = new SiteConfig_ImageDataObjectManager(
$this->owner,
'SlideshowPhotos',
'SlideshowPhoto',
'Image',
array(),
'getCMSFields_forPopup'
);
$idom->setSourceID($this->owner->ID);
$fields->addFieldToTab("Root.Photos", $idom);

}
}

class SiteConfig_ImageDataObjectManager extends ImageDataObjectManager {

function setSourceID($val) {
if (is_numeric($val)) {
$this->sourceID = $val;
}
}

function sourceID() {
if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
return $this->sourceID;
}
return parent::sourceID();
}

}

?>

Avatar
UncleCheese

Forum Moderator, 4094 Posts

1 August 2010 at 5:45am

What does "doesn't work" mean?

Avatar
klikhier

Community Member, 150 Posts

1 August 2010 at 6:07am

Edited: 01/08/2010 6:08am

Sorry, should have mentioned that. Adding photo works fine, but when you click on that photo in image dom to get details the following error occurs:

[User Error] Couldn't run query: SELECT "SlideshowPhoto"."ClassName", "SlideshowPhoto"."Created", "SlideshowPhoto"."LastEdited", "SlideshowPhoto"."Caption", "SlideshowPhoto"."ImageID", "SlideshowPhoto"."CustomSiteConfigID", "SlideshowPhoto"."ID", CASE WHEN "SlideshowPhoto"."ClassName" IS NOT NULL THEN "SlideshowPhoto"."ClassName" ELSE 'SlideshowPhoto' END AS "RecordClassName" FROM "SlideshowPhoto" WHERE ("ParentID" = '1') Unknown column 'ParentID' in 'where clause'
GET /o-original.com/www/admin/EditForm/field/SlideshowPhotos/item/20/edit?ctf[SlideshowPhotos][start]=0&ctf[SlideshowPhotos][per_page]=10&ctf[SlideshowPhotos][showall]=0&ctf[SlideshowPhotos][sort]=Created&ctf[SlideshowPhotos][sort_dir]=DESC&ctf[SlideshowPhotos][search]=&ctf[SlideshowPhotos][filter]=&ctf[SlideshowPhotos][view]=grid&ctf[SlideshowPhotos][imagesize]=100

Line 536 in /.../sapphire/core/model/MySQLDatabase.php

Avatar
UncleCheese

Forum Moderator, 4094 Posts

1 August 2010 at 6:58am

Don't forget to use setParentClass("SiteConfig");