3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1582 Views |
-
How to add a property to a DataObject

3 April 2010 at 4:21am Last edited: 3 April 2010 4:22am
I'm trying to output a lexicon/glossary, and have some problems grouping the output according to first letters.
The lexicon items are DataObjects attached to all pages. In the Page_Controller they are collected
function LexiconAllAggregator() {
$LexiconSet = DataObject::get(
"Lexicon",
"`PageID` IN (" . implode(",", $all_lexicon) . ")",
"Term ASC",
"",
""
);return $LexiconSet ;
}and output in the template
<% control LexiconAllAggregator %>
<h3><a href="{$Top.Link}lexikon/$ID">$Term</a></h3>
<p>$Explanation.FirstParagraph</p>
<% end_control %>Now i want to group them, ie to have divs (with all first letters) after first letter of the terms change. So a new property $Break for $LexiconSet is needed which is should be calculated in the Page_Controller and checked in the template:
<% control LexiconAllAggregator %>
<% if Break %> <div> A B C ... </div> <% end_if %><h3><a href="{$Top.Link}lexikon/$ID">$Term</a></h3>
<p>$Explanation.FirstParagraph</p>
<% end_control %>But I just don't get it how it has to be done to get a new property into the DataObjectSet
I think it will start with something like that$LexiconSetNew = new DataObjectSet();
foreach ( $LexiconSet as $LexiconSetSingle ) {//??????
}
Thanks in advance.
-
Re: How to add a property to a DataObject

7 April 2010 at 4:59pm Last edited: 7 April 2010 4:59pm
Welcome to the forums! What you want to do is something like
foreach ( $LexiconSet as $LexiconSetSingle ) {
$LexiconSetSingle->FieldName = "Hi";
}Or $LexiconSetSingle->setField('FieldName', 'Hi'); if you want. I believe that should work fine - the set should update with the new fields on the object, if they don't you'll have to define a new $output = new DataObjectSet() and after setting that field push the new object onto the output set and return output rather then $LexiconSet.
-
Re: How to add a property to a DataObject

27 October 2012 at 2:58am
This isn't working in ss3?
$images= Image::get()->leftJoin("GalleryImage", "GI.ImageID = File.ID","GI")->where("GI.GalleriesID='".$this->ID."'");
foreach($images as $image) {
$image->setField('TopPos',333);
}
return $images;I can not use TopPos in Template.
-
Re: How to add a property to a DataObject

27 October 2012 at 3:46am
That works...!
Maybe someone can explain why I need to push the DataList into ArrayList$images= DataList::create('Image')->leftJoin("GalleryImage", "GI.ImageID = File.ID","GI")->where("GI.GalleriesID='".$this->ID."'");
$imagesAL=new ArrayList();
$positions=$this->positionErmitteln();
foreach($images as $image) {
$image->TopPos=$positions[$image->ID]['topPos'];
$image->LeftPos=$positions[$image->ID]['leftPos'];
$imagesAL->push($image);
}
return $imagesAL;
| 1582 Views | ||
|
Page:
1
|
Go to Top |


